Skip to content

Commit

Permalink
fix firehose tracer to write the genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Jun 4, 2024
1 parent 26c735e commit 83b874f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func validateBlockChain(blockChain *core.BlockChain, chainConfig *params.ChainCo
return nil
}

func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeConfig, chainId *big.Int, cacheConfig *core.CacheConfig, l1Client arbutil.L1Interface, rollupAddrs chaininfo.RollupAddresses) (ethdb.Database, *core.BlockChain, error) {
func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeConfig, chainId *big.Int, cacheConfig *core.CacheConfig, l1Client arbutil.L1Interface, rollupAddrs chaininfo.RollupAddresses, tracer core.BlockchainLogger) (ethdb.Database, *core.BlockChain, error) {
if !config.Init.Force {
if readOnlyDb, err := stack.OpenDatabaseWithFreezer("l2chaindata", 0, 0, "", "", true); err == nil {
if chainConfig := gethexec.TryReadStoredChainConfig(readOnlyDb); chainConfig != nil {
Expand All @@ -175,7 +175,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
if err != nil {
return chainDb, nil, fmt.Errorf("error pruning: %w", err)
}
l2BlockChain, err := gethexec.GetBlockChain(chainDb, cacheConfig, chainConfig, config.Execution.TxLookupLimit)
l2BlockChain, err := gethexec.GetBlockChain(chainDb, cacheConfig, chainConfig, config.Execution.TxLookupLimit, tracer)
if err != nil {
return chainDb, nil, err
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
if chainConfig == nil {
return chainDb, nil, errors.New("no --init.* mode supplied and chain data not in expected directory")
}
l2BlockChain, err = gethexec.GetBlockChain(chainDb, cacheConfig, chainConfig, config.Execution.TxLookupLimit)
l2BlockChain, err = gethexec.GetBlockChain(chainDb, cacheConfig, chainConfig, config.Execution.TxLookupLimit, tracer)
if err != nil {
return chainDb, nil, err
}
Expand Down Expand Up @@ -356,7 +356,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
log.Warn("Created fake init message as L1Reader is disabled and serialized chain config from init message is not available", "json", string(serializedChainConfig))
}

l2BlockChain, err = gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initDataReader, chainConfig, parsedInitMessage, config.Execution.TxLookupLimit, config.Init.AccountsPerSync)
l2BlockChain, err = gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initDataReader, chainConfig, parsedInitMessage, config.Execution.TxLookupLimit, config.Init.AccountsPerSync, tracer)
if err != nil {
return chainDb, nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers"
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -475,8 +477,12 @@ func mainImpl() int {
}
}
}
var tracer core.BlockchainLogger
if nodeConfig.Node.Firehose {
tracer = tracers.NewFirehoseLogger()
}

chainDb, l2BlockChain, err := openInitializeChainDb(ctx, stack, nodeConfig, new(big.Int).SetUint64(nodeConfig.Chain.ID), gethexec.DefaultCacheConfigFor(stack, &nodeConfig.Execution.Caching), l1Client, rollupAddrs)
chainDb, l2BlockChain, err := openInitializeChainDb(ctx, stack, nodeConfig, new(big.Int).SetUint64(nodeConfig.Chain.ID), gethexec.DefaultCacheConfigFor(stack, &nodeConfig.Execution.Caching), l1Client, rollupAddrs, tracer)
if l2BlockChain != nil {
deferFuncs = append(deferFuncs, func() { l2BlockChain.Stop() })
}
Expand Down Expand Up @@ -536,7 +542,7 @@ func mainImpl() int {
l2BlockChain,
l1Client,
func() *gethexec.Config { return &liveNodeConfig.Get().Execution },
nodeConfig.Node.Firehose,
tracer,
)
if err != nil {
log.Error("failed to create execution node", "err", err)
Expand Down
8 changes: 5 additions & 3 deletions execution/gethexec/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func WriteOrTestGenblock(chainDb ethdb.Database, initData statetransfer.InitData
if storedGenHash == EmptyHash {
// chainDb did not have genesis block. Initialize it.
core.WriteHeadBlock(chainDb, genBlock, prevDifficulty)
rawdb.WriteGenesisStateSpec(chainDb, blockHash, []byte("{}")) // used so Firehose tracer can extract the genesis allocs
log.Info("wrote genesis block", "number", blockNumber, "hash", blockHash)
} else if storedGenHash != blockHash {
return fmt.Errorf("database contains data inconsistent with initialization: database has genesis hash %v but we built genesis hash %v", storedGenHash, blockHash)
Expand Down Expand Up @@ -166,19 +167,20 @@ func WriteOrTestChainConfig(chainDb ethdb.Database, config *params.ChainConfig)
return nil
}

func GetBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, chainConfig *params.ChainConfig, txLookupLimit uint64) (*core.BlockChain, error) {
func GetBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, chainConfig *params.ChainConfig, txLookupLimit uint64, tracer core.BlockchainLogger) (*core.BlockChain, error) {
engine := arbos.Engine{
IsSequencer: true,
}

vmConfig := vm.Config{
EnablePreimageRecording: false,
Tracer: tracer,
}

return core.NewBlockChain(chainDb, cacheConfig, chainConfig, nil, nil, engine, vmConfig, shouldPreserveFalse, &txLookupLimit)
}

func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, txLookupLimit uint64, accountsPerSync uint) (*core.BlockChain, error) {
func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, txLookupLimit uint64, accountsPerSync uint, tracer core.BlockchainLogger) (*core.BlockChain, error) {
err := WriteOrTestGenblock(chainDb, initData, chainConfig, initMessage, accountsPerSync)
if err != nil {
return nil, err
Expand All @@ -187,7 +189,7 @@ func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig
if err != nil {
return nil, err
}
return GetBlockChain(chainDb, cacheConfig, chainConfig, txLookupLimit)
return GetBlockChain(chainDb, cacheConfig, chainConfig, txLookupLimit, tracer)
}

// Don't preserve reorg'd out blocks
Expand Down
8 changes: 3 additions & 5 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
Expand Down Expand Up @@ -150,7 +149,7 @@ func CreateExecutionNode(
l2BlockChain *core.BlockChain,
l1client arbutil.L1Interface,
configFetcher ConfigFetcher,
withFirehose bool,
tracer core.BlockchainLogger,
) (*ExecutionNode, error) {
config := configFetcher()
execEngine, err := NewExecutionEngine(l2BlockChain)
Expand All @@ -160,9 +159,8 @@ func CreateExecutionNode(
if err != nil {
return nil, err
}
if withFirehose {
fh := tracers.NewFirehoseLogger()
execEngine.SetLogger(fh)
if tracer != nil {
execEngine.SetLogger(tracer)
}
recorder := NewBlockRecorder(&config.RecordingDatabase, execEngine, chainDB)
var txPublisher TransactionPublisher
Expand Down

0 comments on commit 83b874f

Please sign in to comment.