diff --git a/core/blockchain.go b/core/blockchain.go index 956801186e..3599525090 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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() @@ -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() diff --git a/node/node_cross_link.go b/node/node_cross_link.go index a19cbfcd5b..59d1a666bd 100644 --- a/node/node_cross_link.go +++ b/node/node_cross_link.go @@ -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 diff --git a/node/node_handler.go b/node/node_handler.go index d9ed591a23..a28ae4ce56 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -373,11 +373,11 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) error { Int("numStakingTx", len(newBlock.StakingTransactions())). Err(err). Msg("[VerifyNewBlock] Cannot Verify New Block!!!") - return ctxerror.New("[VerifyNewBlock] Cannot Verify New Block!!!", - "blockHash", newBlock.Hash(), - "numTx", len(newBlock.Transactions()), - "numStakingTx", len(newBlock.StakingTransactions()), - ).WithCause(err) + return errors.Errorf( + "[VerifyNewBlock] Cannot Verify New Block!!! block-hash %s txn-count %d", + newBlock.Hash().Hex(), + len(newBlock.Transactions()), + ) } // Verify cross links