diff --git a/core/blockchain.go b/core/blockchain.go index 42e35b3fa6..591e129efc 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -160,7 +160,7 @@ type BlockchainLogger interface { state.StateLogger OnBlockStart(*types.Block) OnBlockEnd(td *big.Int, err error) - OnGenesisBlock(*types.Block) + OnGenesisBlock(*types.Block, GenesisAlloc) } // BlockChain represents the canonical chain given a database with a genesis @@ -1834,6 +1834,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) } return it.index, err } + // Update the metrics touched during block commit accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them diff --git a/core/genesis.go b/core/genesis.go index 2d84efcfde..c5f615210b 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -485,7 +485,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database, bcLogger Bloc return nil, errors.New("can't start clique chain without signers") } if bcLogger != nil { - bcLogger.OnGenesisBlock(block) + bcLogger.OnGenesisBlock(block, g.Alloc) } // All the checks has passed, flush the states derived from the genesis // specification as well as the specification itself into the provided diff --git a/eth/tracers/firehose.go b/eth/tracers/firehose.go index 3b62d77b7d..fbcde89c20 100644 --- a/eth/tracers/firehose.go +++ b/eth/tracers/firehose.go @@ -252,33 +252,19 @@ func (f *Firehose) OnBlockStart(b *types.Block) { } func (f *Firehose) OnBlockEnd(td *big.Int, err error) { - // OnBlockEnd can be called while a transaction/call is still in progress, so must only assert that we are in a block - f.ensureInBlock() - if err == nil { - // No reset, next step is either OnBlockValidationError (skip and reset) or OnBlockWritten (flush and reset) + f.ensureInBlockAndNotInTrx() + f.block.Header.TotalDifficulty = pbeth.BigIntFromNative(td) + f.printBlockToFirehose(f.block) } else { - // OnBlockEnd with error means that we could have been in any state - f.resetBlock() - f.resetTransaction() - f.resetCall() + // An error occurred, could have happen in transaction/call context, we must not check if in trx, only check in block + f.ensureInBlock() } -} - -func (f *Firehose) OnBlockValidationError(block *types.Block, err error) { - f.ensureInBlockAndNotInTrx() - - fmt.Fprintf(os.Stderr, "OnBlockValidationError: b=%v, err=%v\n", block.NumberU64(), err) - f.resetBlock() -} - -func (f *Firehose) OnBlockWritten() { - f.ensureInBlockAndNotInTrx() - - f.printBlockToFirehose(f.block) f.resetBlock() + f.resetTransaction() + f.resetCall() } func (f *Firehose) OnGenesisBlock(b *types.Block, alloc core.GenesisAlloc) { diff --git a/eth/tracers/printer.go b/eth/tracers/printer.go index 98c7417831..67dd50cb2f 100644 --- a/eth/tracers/printer.go +++ b/eth/tracers/printer.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" ) @@ -29,7 +30,7 @@ func (p *Printer) CaptureEnd(output []byte, gasUsed uint64, err error) { // CaptureState implements the EVMLogger interface to trace a single step of VM execution. func (p *Printer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) { - //fmt.Printf("CaptureState: pc=%v, op=%v, gas=%v, cost=%v, scope=%v, rData=%v, depth=%v, err=%v\n", pc, op, gas, cost, scope, rData, depth, err) + //fmt.Printf("CaptureState: pc=%v, op=%v, gas=%v, cost=%v, scope=%v, rData=%s, depth=%v, err=%v\n", pc, op, gas, cost, scope, hexutil.Bytes(rData), depth, err) } // CaptureFault implements the EVMLogger interface to trace an execution fault. @@ -78,7 +79,7 @@ func (p *Printer) OnBlockEnd(td *big.Int, err error) { fmt.Printf("OnBlockEnd: td=%v, err=%v\n", td, err) } -func (p *Printer) OnGenesisBlock(b *types.Block) { +func (p *Printer) OnGenesisBlock(b *types.Block, _ core.GenesisAlloc) { fmt.Printf("OnGenesisBlock: b=%v\n", b.NumberU64()) }