Skip to content

Commit

Permalink
Fixes various issues with incorrect block validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Jul 28, 2024
1 parent bbfca6a commit f7b5e88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions node_util/block_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func HashBlock(block Block, blockHeight int) [64]byte {
if err != nil {
panic(err)
}
blockCpy.MiningTime = time.Minute
blockCpy.TimeVerifiers = []PublicKey{}
blockCpy.TimeVerifierSignatures = []Signature{}
blockCpy.Timestamp = time.Time{}
for i := range block.Transactions {
blockCpy.Transactions[i].Timestamp = time.Time{}
blockCpy.Transactions[i].Body = []byte{}
Expand Down
2 changes: 1 addition & 1 deletion node_util/create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func CreateBlock() (Block, error) {
}
}
timeVerificationTimestamp := time.Now()
if Env.Upgrades.Yangon <= len(Blockchain) {
if Env.Upgrades.Yangon <= len(Blockchain) && Env.Upgrades.Yangon != -1 {
block.MiningTime = timeVerificationTimestamp.Sub(previousBlock.Timestamp.Add(previousBlock.MiningTime))
} else {
block.MiningTime = time.Since(start)
Expand Down
4 changes: 2 additions & 2 deletions node_util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ func HandleVerifyTimeRequest(w http.ResponseWriter, req *http.Request) {
// Get the time mining finished
if Env.Upgrades.Yangon <= len(Blockchain) && Env.Upgrades.Yangon != -1 {
previousBlockFinishedTime := Blockchain[len(Blockchain)-1].Timestamp.Add(Blockchain[len(Blockchain)-1].MiningTime)
currentTime = previousBlockFinishedTime.Add(block.MiningTime)
miningFinishedTime = previousBlockFinishedTime.Add(block.MiningTime)
} else {
currentTime = block.Timestamp.Add(block.MiningTime)
miningFinishedTime = block.Timestamp.Add(block.MiningTime)
}
// Check if the time the block was mined is within a reasonable range of the current time
// It cannot be in the future, and it cannot be more than 10 seconds in the past
Expand Down

0 comments on commit f7b5e88

Please sign in to comment.