Skip to content

Commit

Permalink
fix(node): total amount verification is wrong (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyPansier authored Jan 31, 2023
1 parent f5e8f49 commit d7ee5b6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node/protocol/verification/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func (blockchain *Blockchain) CalculateTotalAmount(currentTimestamp int64, block
var totalAmount uint64
var lastTimestamp int64
for _, block := range blockchain.blockResponses {
if block.Timestamp > currentTimestamp {
break
}
for _, registeredAddress := range block.RegisteredAddresses {
if blockchainAddress == registeredAddress {
if totalAmount > 0 {
Expand Down Expand Up @@ -447,7 +450,7 @@ func (blockchain *Blockchain) verifyBlock(neighborBlock *Block, previousBlock *B
return errors.New("neighbor block reward exceeds the consented one")
}
for senderAddress, totalTransactionsValue := range totalTransactionsValueBySenderAddress {
amount := neighborBlockchain.CalculateTotalAmount(currentBlockTimestamp, senderAddress)
amount := neighborBlockchain.CalculateTotalAmount(previousBlockTimestamp, senderAddress)
if totalTransactionsValue > amount {
return errors.New("neighbor block total transactions value exceeds its sender wallet amount")
}
Expand Down

0 comments on commit d7ee5b6

Please sign in to comment.