Skip to content

Commit

Permalink
feat(taiko-client): remove hardcoded protocol configs after protocol …
Browse files Browse the repository at this point in the history
…cleanup (#18351)
  • Loading branch information
davidtaikocha committed Nov 3, 2024
1 parent 1c4e808 commit 75c0b26
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 102 deletions.
79 changes: 0 additions & 79 deletions packages/taiko-client/bindings/encoding/protocol_config.go

This file was deleted.

8 changes: 6 additions & 2 deletions packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/state"
Expand Down Expand Up @@ -66,14 +65,19 @@ func NewSyncer(
return nil, fmt.Errorf("failed to initialize anchor constructor: %w", err)
}

protocolConfigs, err := rpc.GetProtocolConfigs(client.TaikoL1, &bind.CallOpts{Context: ctx})
if err != nil {
return nil, err
}

return &Syncer{
ctx: ctx,
rpc: client,
state: state,
progressTracker: progressTracker,
anchorConstructor: constructor,
txListDecompressor: txListDecompressor.NewTxListDecompressor(
uint64(encoding.GetProtocolConfig(client.L2.ChainID.Uint64()).BlockMaxGasLimit),
uint64(protocolConfigs.BlockMaxGasLimit),
rpc.BlockMaxTxListBytes,
client.L2.ChainID,
),
Expand Down
6 changes: 4 additions & 2 deletions packages/taiko-client/driver/chain_syncer/blob/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/state"
Expand Down Expand Up @@ -162,8 +161,11 @@ func (s *BlobSyncerTestSuite) TestTreasuryIncome() {
s.Greater(headAfter, headBefore)
s.True(balanceAfter.Cmp(balance) > 0)

protocolConfigs, err := rpc.GetProtocolConfigs(s.RPCClient.TaikoL1, nil)
s.Nil(err)

var hasNoneAnchorTxs bool
chainConfig := config.NewChainConfig(encoding.GetProtocolConfig(s.RPCClient.L2.ChainID.Uint64()))
chainConfig := config.NewChainConfig(&protocolConfigs)
for i := headBefore + 1; i <= headAfter; i++ {
block, err := s.RPCClient.L2.BlockByNumber(context.Background(), new(big.Int).SetUint64(i))
s.Nil(err)
Expand Down
9 changes: 7 additions & 2 deletions packages/taiko-client/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
chainSyncer "github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/state"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
Expand Down Expand Up @@ -174,9 +173,15 @@ func (d *Driver) ChainSyncer() *chainSyncer.L2ChainSyncer {

// reportProtocolStatus reports some protocol status intervally.
func (d *Driver) reportProtocolStatus() {
protocolConfigs, err := rpc.GetProtocolConfigs(d.rpc.TaikoL1, &bind.CallOpts{Context: d.ctx})
if err != nil {
log.Error("Failed to get protocol configs", "error", err)
return
}

var (
ticker = time.NewTicker(protocolStatusReportInterval)
maxNumBlocks = encoding.GetProtocolConfig(d.rpc.L2.ChainID.Uint64()).BlockMaxProposals
maxNumBlocks = protocolConfigs.BlockMaxProposals
)
d.wg.Add(1)

Expand Down
11 changes: 7 additions & 4 deletions packages/taiko-client/driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"sync"
"sync/atomic"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -64,10 +62,15 @@ func (s *State) init(ctx context.Context) error {
return err
}

protocolConfigs, err := rpc.GetProtocolConfigs(s.rpc.TaikoL1, &bind.CallOpts{Context: ctx})
if err != nil {
return err
}

s.GenesisL1Height = new(big.Int).SetUint64(stateVars.A.GenesisHeight)
log.Info("Genesis L1 height", "height", stateVars.A.GenesisHeight)
s.OnTakeForkHeight = new(big.Int).SetUint64(protocolConfigs.OntakeForkHeight)

s.OnTakeForkHeight = new(big.Int).SetUint64(encoding.GetProtocolConfig(s.rpc.L2.ChainID.Uint64()).OntakeForkHeight)
log.Info("Genesis L1 height", "height", stateVars.A.GenesisHeight)
log.Info("OnTake fork height", "height", s.OnTakeForkHeight)

// Set the L2 head's latest known L1 origin as current L1 sync cursor.
Expand Down
6 changes: 4 additions & 2 deletions packages/taiko-client/internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/phayes/freeport"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
)
Expand Down Expand Up @@ -202,12 +201,15 @@ func (s *ClientTestSuite) ProposeValidBlock(
ontakeForkHeight, err := s.RPCClient.TaikoL2.OntakeForkHeight(nil)
s.Nil(err)

protocolConfigs, err := rpc.GetProtocolConfigs(s.RPCClient.TaikoL1, nil)
s.Nil(err)

baseFee, err := s.RPCClient.CalculateBaseFee(
context.Background(),
l2Head,
l1Head.Number,
l2Head.Number.Uint64()+1 >= ontakeForkHeight,
&encoding.InternlDevnetProtocolConfig.BaseFeeConfig,
&protocolConfigs.BaseFeeConfig,
l1Head.Time,
)
s.Nil(err)
Expand Down
7 changes: 6 additions & 1 deletion packages/taiko-client/pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {
}
)

protocolConfigs, err := GetProtocolConfigs(c.TaikoL1, &bind.CallOpts{Context: ctxWithTimeout})
if err != nil {
return err
}

// If chain actives ontake fork from genesis, we need to fetch the genesis block hash from `BlockVerifiedV2` event.
if encoding.GetProtocolConfig(c.L2.ChainID.Uint64()).OntakeForkHeight == 0 {
if protocolConfigs.OntakeForkHeight == 0 {
// Fetch the genesis `BlockVerified2` event.
iter, err := c.TaikoL1.FilterBlockVerifiedV2(filterOpts, []*big.Int{common.Big0}, nil)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions packages/taiko-client/pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ var (
}
)

// GetProtocolConfigs gets the protocol configs from TaikoL1 contract.
func GetProtocolConfigs(
taikoL1Client *bindings.TaikoL1Client,
opts *bind.CallOpts,
) (bindings.TaikoDataConfig, error) {
var cancel context.CancelFunc
if opts == nil {
opts = &bind.CallOpts{Context: context.Background()}
}
opts.Context, cancel = CtxWithTimeoutOrDefault(opts.Context, defaultTimeout)
defer cancel()

return taikoL1Client.GetConfig(opts)
}

// GetProtocolStateVariables gets the protocol states from TaikoL1 contract.
func GetProtocolStateVariables(
taikoL1Client *bindings.TaikoL1Client,
Expand Down
7 changes: 5 additions & 2 deletions packages/taiko-client/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ func (p *Proposer) InitFromConfig(
}

// Protocol configs
p.protocolConfigs = encoding.GetProtocolConfig(p.rpc.L2.ChainID.Uint64())

protocolConfigs, err := rpc.GetProtocolConfigs(p.rpc.TaikoL1, &bind.CallOpts{Context: p.ctx})
if err != nil {
return fmt.Errorf("failed to get protocol configs: %w", err)
}
p.protocolConfigs = &protocolConfigs
log.Info("Protocol configs", "configs", p.protocolConfigs)

if txMgr == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/testutils"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
)

type TransactionBuilderTestSuite struct {
Expand All @@ -27,8 +27,10 @@ func (s *TransactionBuilderTestSuite) SetupTest() {
l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)

protocolConfig := encoding.GetProtocolConfig(s.RPCClient.L2.ChainID.Uint64())
chainConfig := config.NewChainConfig(protocolConfig)
protocolConfigs, err := rpc.GetProtocolConfigs(s.RPCClient.TaikoL1, nil)
s.Nil(err)

chainConfig := config.NewChainConfig(&protocolConfigs)

s.calldataTxBuilder = NewCalldataTransactionBuilder(
s.RPCClient,
Expand Down
14 changes: 9 additions & 5 deletions packages/taiko-client/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Prover struct {
guardianProverHeartbeater guardianProverHeartbeater.BlockSenderHeartbeater

// Contract configurations
protocolConfig *bindings.TaikoDataConfig
protocolConfigs *bindings.TaikoDataConfig

// States
sharedState *state.SharedState
Expand Down Expand Up @@ -121,10 +121,14 @@ func InitFromConfig(
}

// Configs
p.protocolConfig = encoding.GetProtocolConfig(p.rpc.L2.ChainID.Uint64())
log.Info("Protocol configs", "configs", p.protocolConfig)
protocolConfigs, err := rpc.GetProtocolConfigs(p.rpc.TaikoL1, &bind.CallOpts{Context: p.ctx})
if err != nil {
return fmt.Errorf("failed to get protocol configs: %w", err)
}
p.protocolConfigs = &protocolConfigs
log.Info("Protocol configs", "configs", p.protocolConfigs)

chBufferSize := p.protocolConfig.BlockMaxProposals
chBufferSize := p.protocolConfigs.BlockMaxProposals
p.proofGenerationCh = make(chan *proofProducer.ProofWithHeader, chBufferSize)
p.assignmentExpiredCh = make(chan metadata.TaikoBlockMetaData, chBufferSize)
p.proofSubmissionCh = make(chan *proofProducer.ProofRequestBody, p.cfg.Capacity)
Expand Down Expand Up @@ -280,7 +284,7 @@ func (p *Prover) eventLoop() {
defer forceProvingTicker.Stop()

// Channels
chBufferSize := p.protocolConfig.BlockMaxProposals
chBufferSize := p.protocolConfigs.BlockMaxProposals
blockProposedCh := make(chan *bindings.TaikoL1ClientBlockProposed, chBufferSize)
blockVerifiedCh := make(chan *bindings.TaikoL1ClientBlockVerified, chBufferSize)
transitionProvedCh := make(chan *bindings.TaikoL1ClientTransitionProved, chBufferSize)
Expand Down

0 comments on commit 75c0b26

Please sign in to comment.