Skip to content

Commit 5b8530a

Browse files
authored
Merge pull request #1385 from CortexFoundation/dev
add block number in logs
2 parents 10c772f + 5417e5c commit 5b8530a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

core/state/statedb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ func (s *StateDB) AddLog(log *types.Log) {
197197
s.logSize++
198198
}
199199

200-
func (s *StateDB) GetLogs(hash, blockHash common.Hash) []*types.Log {
200+
func (s *StateDB) GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log {
201201
logs := s.logs[hash]
202202
for _, l := range logs {
203+
l.BlockNumber = blockNumber
203204
l.BlockHash = blockHash
204205
}
205206
return s.logs[hash]

core/state/statedb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
420420
return fmt.Errorf("got GetRefund() == %d, want GetRefund() == %d",
421421
state.GetRefund(), checkstate.GetRefund())
422422
}
423-
if !reflect.DeepEqual(state.GetLogs(common.Hash{}, common.Hash{}), checkstate.GetLogs(common.Hash{}, common.Hash{})) {
423+
if !reflect.DeepEqual(state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{})) {
424424
return fmt.Errorf("got GetLogs(common.Hash{}) == %v, want GetLogs(common.Hash{}) == %v",
425-
state.GetLogs(common.Hash{}, common.Hash{}), checkstate.GetLogs(common.Hash{}, common.Hash{}))
425+
state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{}))
426426
}
427427
return nil
428428
}

core/state_processor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8484
return nil, nil, 0, err
8585
}
8686
statedb.Prepare(tx.Hash(), i)
87-
receipt, _, err := applyTransaction(msg, p.config, nil, gp, qp, statedb, header, blockNumber, blockHash, tx, usedGas, vmenv)
87+
receipt, _, err := applyTransaction(msg, p.config, gp, qp, statedb, header, blockNumber, blockHash, tx, usedGas, vmenv)
8888
if err != nil {
8989
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
9090
}
@@ -106,7 +106,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
106106
// and uses the input parameters for its environment. It returns the receipt
107107
// for the transaction, gas used and an error if the transaction failed,
108108
// indicating the block was invalid.
109-
func applyTransaction(msg types.Message, config *params.ChainConfig, author *common.Address, gp *GasPool, qp *QuotaPool, statedb *state.StateDB, header *types.Header, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, cvm *vm.CVM) (*types.Receipt, uint64, error) {
109+
func applyTransaction(msg types.Message, config *params.ChainConfig, gp *GasPool, qp *QuotaPool, statedb *state.StateDB, header *types.Header, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, cvm *vm.CVM) (*types.Receipt, uint64, error) {
110110
// Create a new context to be used in the CVM environment
111111
txContext := NewCVMTxContext(msg)
112112
// Update the evm with the new transaction context.
@@ -146,7 +146,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, author *com
146146
receipt.ContractAddress = crypto.CreateAddress(cvm.TxContext.Origin, tx.Nonce())
147147
}
148148
// Set the receipt logs and create a bloom for filtering
149-
receipt.Logs = statedb.GetLogs(tx.Hash(), blockHash)
149+
receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash)
150150
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
151151

152152
receipt.BlockHash = blockHash
@@ -169,5 +169,5 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
169169
// Create a new context to be used in the CVM environment
170170
blockContext := NewCVMBlockContext(header, bc, author)
171171
vmenv := vm.NewCVM(blockContext, vm.TxContext{}, statedb, config, cfg)
172-
return applyTransaction(msg, config, author, gp, qp, statedb, header, header.Number, header.Hash(), tx, usedGas, vmenv)
172+
return applyTransaction(msg, config, gp, qp, statedb, header, header.Number, header.Hash(), tx, usedGas, vmenv)
173173
}

0 commit comments

Comments
 (0)