Skip to content

Commit

Permalink
fix bug in core/blockchain.go where incorrect receipt data was genera…
Browse files Browse the repository at this point in the history
…ted in SetReceiptsData
  • Loading branch information
denniswon committed Apr 10, 2020
1 parent 7e30b31 commit 7cc9d50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
29 changes: 13 additions & 16 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,22 +890,20 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
return errors.New("transaction+stakingTransactions and receipt count mismatch")
}

for j := 0; j < len(transactions); j++ {
// The used gas can be calculated based on previous receipts
if len(receipts) > 0 && len(transactions) > 0 {
receipts[0].GasUsed = receipts[0].CumulativeGasUsed
}
for j := 1; j < len(transactions); j++ {
// The transaction hash can be retrieved from the transaction itself
receipts[j].TxHash = transactions[j].Hash()

receipts[j].GasUsed = receipts[j].CumulativeGasUsed - receipts[j-1].CumulativeGasUsed
// The contract address can be derived from the transaction itself
if transactions[j].To() == nil {
// Deriving the signer is expensive, only do if it's actually needed
from, _ := types.Sender(signer, transactions[j])
receipts[j].ContractAddress = crypto.CreateAddress(from, transactions[j].Nonce())
}
// The used gas can be calculated based on previous receipts
if j == 0 {
receipts[j].GasUsed = receipts[j].CumulativeGasUsed
} else {
receipts[j].GasUsed = receipts[j].CumulativeGasUsed - receipts[j-1].CumulativeGasUsed
}
// The derived log fields can simply be set from the block and transaction
for k := 0; k < len(receipts[j].Logs); k++ {
receipts[j].Logs[k].BlockNumber = block.NumberU64()
Expand All @@ -916,17 +914,16 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
logIndex++
}
}

// The used gas can be calculated based on previous receipts
if len(receipts) > len(transactions) && len(stakingTransactions) > 0 {
receipts[len(transactions)].GasUsed = receipts[len(transactions)].CumulativeGasUsed
}
// in a block, txns are processed before staking txns
for j := len(transactions); j < len(transactions)+len(stakingTransactions); j++ {
for j := len(transactions) + 1; j < len(transactions)+len(stakingTransactions); j++ {
// The transaction hash can be retrieved from the staking transaction itself
receipts[j].TxHash = stakingTransactions[j].Hash()

// The used gas can be calculated based on previous receipts
if j == 0 {
receipts[j].GasUsed = receipts[j].CumulativeGasUsed
} else {
receipts[j].GasUsed = receipts[j].CumulativeGasUsed - receipts[j-1].CumulativeGasUsed
}
receipts[j].GasUsed = receipts[j].CumulativeGasUsed - receipts[j-1].CumulativeGasUsed
// The derived log fields can simply be set from the block and transaction
for k := 0; k < len(receipts[j].Logs); k++ {
receipts[j].Logs[k].BlockNumber = block.NumberU64()
Expand Down
12 changes: 0 additions & 12 deletions node/node_cross_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,9 @@ func (node *Node) VerifyBlockCrossLinks(block *types.Block) error {
// Add slash for exist same blocknum but different crosslink
return errAlreadyExist
}
<<<<<<< HEAD
if err := node.VerifyCrossLink(crossLink); err != nil {
return errors.Wrapf(err, "cannot VerifyBlockCrossLinks")

=======
if err = node.VerifyCrossLink(crossLink); err != nil {
return ctxerror.New("cannot VerifyBlockCrossLinks",
"blockHash", block.Hash(),
"blockNum", block.Number(),
"crossLinkShard", crossLink.ShardID(),
"crossLinkBlock", crossLink.BlockNum(),
"numTx", len(block.Transactions()),
"numStakingTx", len(block.StakingTransactions()),
).WithCause(err)
>>>>>>> Updating all sources of block.Transactions and do the corresponding work for block staking txns
}
}
return nil
Expand Down

0 comments on commit 7cc9d50

Please sign in to comment.