Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove precompilesgen dependency from headerreader #1851

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/solgen/go/challengegen"
"github.com/offchainlabs/nitro/solgen/go/ospgen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/contracts"
Expand Down Expand Up @@ -235,7 +236,8 @@ func GenerateRollupConfig(prod bool, wasmModuleRoot common.Hash, rollupOwner com
}

func DeployOnL1(ctx context.Context, l1client arbutil.L1Interface, deployAuth *bind.TransactOpts, batchPoster common.Address, authorizeValidators uint64, readerConfig headerreader.ConfigFetcher, config rollupgen.Config) (*chaininfo.RollupAddresses, error) {
l1Reader, err := headerreader.New(ctx, l1client, readerConfig)
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err := headerreader.New(ctx, l1client, readerConfig, arbSys)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -611,7 +613,8 @@ func createNodeImpl(

var l1Reader *headerreader.HeaderReader
if config.ParentChainReader.Enable {
l1Reader, err = headerreader.New(ctx, l1client, func() *headerreader.Config { return &configFetcher.Get().ParentChainReader })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err = headerreader.New(ctx, l1client, func() *headerreader.Config { return &configFetcher.Get().ParentChainReader }, arbSys)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/daserver/daserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import (
flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"

"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/headerreader"
)

Expand Down Expand Up @@ -196,7 +198,8 @@ func startup() error {
if err != nil {
return err
}
l1Reader, err = headerreader.New(ctx, l1Client, func() *headerreader.Config { return &headerreader.DefaultConfig }) // TODO: config
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err = headerreader.New(ctx, l1Client, func() *headerreader.Config { return &headerreader.DefaultConfig }, arbSys) // TODO: config
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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/types"
"github.com/ethereum/go-ethereum/crypto"
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Expand All @@ -48,6 +49,7 @@ import (
"github.com/offchainlabs/nitro/cmd/util"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
_ "github.com/offchainlabs/nitro/nodeInterface"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/headerreader"
Expand Down Expand Up @@ -354,7 +356,8 @@ func mainImpl() int {
flag.Usage()
log.Crit("--node.validator.only-create-wallet-contract requires --node.validator.use-smart-contract-wallet")
}
l1Reader, err := headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err := headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader }, arbSys)
if err != nil {
log.Crit("failed to get L1 headerreader", "error", err)

Expand Down
4 changes: 3 additions & 1 deletion system_tests/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/util/signature"
)
Expand Down Expand Up @@ -233,7 +234,8 @@ func TestDASComplexConfigAndRestMirror(t *testing.T) {
chainConfig := params.ArbitrumDevTestDASChainConfig()
l1info, l1client, _, l1stack := createTestL1BlockChain(t, nil)
defer requireClose(t, l1stack)
l1Reader, err := headerreader.New(ctx, l1client, func() *headerreader.Config { return &headerreader.TestConfig })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err := headerreader.New(ctx, l1client, func() *headerreader.Config { return &headerreader.TestConfig }, arbSys)
Require(t, err)
l1Reader.Start(ctx)
defer l1Reader.StopAndWait()
Expand Down
17 changes: 9 additions & 8 deletions util/headerreader/header_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/stopwaiter"
flag "github.com/spf13/pflag"
)

type ArbSysInterface interface {
ArbBlockNumber(*bind.CallOpts) (*big.Int, error)
}

type HeaderReader struct {
stopwaiter.StopWaiter
config ConfigFetcher
client arbutil.L1Interface
isParentChainArbitrum bool
arbSys *precompilesgen.ArbSys
arbSys ArbSysInterface

chanMutex sync.RWMutex
// All fields below require the chanMutex
Expand Down Expand Up @@ -91,25 +94,23 @@ var TestConfig = Config{
UseFinalityData: false,
}

func New(ctx context.Context, client arbutil.L1Interface, config ConfigFetcher) (*HeaderReader, error) {
func New(ctx context.Context, client arbutil.L1Interface, config ConfigFetcher, arbSysPrecompile ArbSysInterface) (*HeaderReader, error) {
isParentChainArbitrum := false
var arbSys *precompilesgen.ArbSys
codeAt, err := client.CodeAt(ctx, types.ArbSysAddress, nil)
if err != nil {
return nil, err
}
if len(codeAt) != 0 {
isParentChainArbitrum = true
arbSys, err = precompilesgen.NewArbSys(types.ArbSysAddress, client)
if err != nil {
return nil, err
if arbSysPrecompile == nil {
return nil, errors.New("unable to create ArbSys from precompilesgen")
}
}
return &HeaderReader{
client: client,
config: config,
isParentChainArbitrum: isParentChainArbitrum,
arbSys: arbSys,
arbSys: arbSysPrecompile,
outChannels: make(map[chan<- *types.Header]struct{}),
outChannelsBehind: make(map[chan<- *types.Header]struct{}),
safe: cachedHeader{rpcBlockNum: big.NewInt(rpc.SafeBlockNumber.Int64())},
Expand Down