Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
merge main, + update implementation to alpha-4-base branch, + valid p…
Browse files Browse the repository at this point in the history
…roof submissions
  • Loading branch information
cyberhorsey committed Jun 26, 2023
1 parent a309a09 commit 57e127b
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 1,151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: staking_tokenomicis_1
ref: alpha-4-base

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b2d980fac7a1fd87a3b0a294c6cb911e4b89c4cb
1bca3c719f4fdd2d8b52d5e6541f1088b30f5326
317 changes: 94 additions & 223 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

1,493 changes: 607 additions & 886 deletions bindings/gen_taiko_prover_pool_l1.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func NewSyncer(
progressTracker: progressTracker,
anchorConstructor: constructor,
txListValidator: txListValidator.NewTxListValidator(
configs.BlockMaxGasLimit,
configs.MaxTransactionsPerBlock,
configs.MaxBytesPerTxList,
uint64(configs.BlockMaxGasLimit),
configs.BlockMaxTransactions,
configs.BlockMaxTxListBytes,
rpc.L2ChainID,
),
}, nil
Expand Down Expand Up @@ -176,7 +176,6 @@ func (s *Syncer) onBlockProposed(
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
"BlockFee", event.BlockFee,
"Removed", event.Raw.Removed,
)

Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (d *Driver) reportProtocolStatus() {
return err
}

maxNumBlocks = configs.MaxNumProposedBlocks.Uint64()
maxNumBlocks = configs.BlockMaxProposals.Uint64()
return nil
},
backoff.NewConstantBackOff(d.backOffRetryInterval),
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (c *Client) WaitL1Origin(ctx context.Context, blockID *big.Int) (*rawdb.L1O
func (c *Client) GetPoolContent(
ctx context.Context,
maxTransactionsPerBlock uint64,
blockMaxGasLimit uint64,
blockMaxGasLimit uint32,
maxBytesPerTxList uint64,
locals []common.Address,
) ([]types.Transactions, error) {
Expand Down
6 changes: 3 additions & 3 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) {
p.protocolConfigs = &protocolConfigs

if cfg.MinBlockGasLimit != 0 {
if cfg.MinBlockGasLimit > p.protocolConfigs.BlockMaxGasLimit {
if uint32(cfg.MinBlockGasLimit) > p.protocolConfigs.BlockMaxGasLimit {
return fmt.Errorf(
"minimal block gas limit too large, set: %d, limit: %d",
cfg.MinBlockGasLimit,
Expand Down Expand Up @@ -203,9 +203,9 @@ func (p *Proposer) ProposeOp(ctx context.Context) error {

txLists, err := p.rpc.GetPoolContent(
ctx,
p.protocolConfigs.MaxTransactionsPerBlock,
p.protocolConfigs.BlockMaxTransactions,
p.protocolConfigs.BlockMaxGasLimit,
p.protocolConfigs.MaxBytesPerTxList,
p.protocolConfigs.BlockMaxTxListBytes,
p.locals,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions prover/proof_producer/zkevm_rpcd_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func (p *ZkevmRpcdProducer) requestProof(opts *ProofRequestOptions) (*RpcdOutput
Graffiti: opts.Graffiti,
GasUsed: opts.GasUsed,
ParentGasUsed: opts.ParentGasUsed,
BlockMaxGasLimit: p.ProtocolConfig.BlockMaxGasLimit,
MaxTransactionsPerBlock: p.ProtocolConfig.MaxTransactionsPerBlock,
MaxBytesPerTxList: p.ProtocolConfig.MaxBytesPerTxList,
BlockMaxGasLimit: uint64(p.ProtocolConfig.BlockMaxGasLimit),
MaxTransactionsPerBlock: p.ProtocolConfig.BlockMaxTransactions,
MaxBytesPerTxList: p.ProtocolConfig.BlockMaxTxListBytes,
}},
}

Expand Down
20 changes: 9 additions & 11 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {

p.submitProofTxMutex = &sync.Mutex{}
p.txListValidator = txListValidator.NewTxListValidator(
p.protocolConfigs.BlockMaxGasLimit,
p.protocolConfigs.MaxTransactionsPerBlock,
p.protocolConfigs.MaxBytesPerTxList,
uint64(p.protocolConfigs.BlockMaxGasLimit),
p.protocolConfigs.BlockMaxTransactions,
p.protocolConfigs.BlockMaxTxListBytes,
p.rpc.L2ChainID,
)
p.proverAddress = crypto.PubkeyToAddress(p.cfg.L1ProverPrivKey.PublicKey)

chBufferSize := p.protocolConfigs.MaxNumProposedBlocks.Uint64()
chBufferSize := p.protocolConfigs.BlockMaxProposals.Uint64()
p.blockProposedCh = make(chan *bindings.TaikoL1ClientBlockProposed, chBufferSize)
p.blockVerifiedCh = make(chan *bindings.TaikoL1ClientBlockVerified, chBufferSize)
p.blockProvenCh = make(chan *bindings.TaikoL1ClientBlockProven, chBufferSize)
Expand Down Expand Up @@ -235,7 +235,7 @@ func (p *Prover) eventLoop() {
// If there is no new block verification in `proofCooldownPeriod * 2` seconeds, and the current prover is
// a special prover, we will go back to try proving the block whose id is `lastVerifiedBlockId + 1`.
verificationCheckTicker := time.NewTicker(
time.Duration(p.protocolConfigs.ProofCooldownPeriod.Uint64()*2) * time.Second,
time.Duration(p.protocolConfigs.ProofRegularCooldown.Uint64()*2) * time.Second,
)
defer verificationCheckTicker.Stop()

Expand Down Expand Up @@ -376,7 +376,6 @@ func (p *Prover) onBlockProposed(
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
"BlockFee", event.BlockFee,
"Removed", event.Raw.Removed,
)
metrics.ProverReceivedProposedBlockGauge.Update(event.Id.Int64())
Expand Down Expand Up @@ -418,14 +417,13 @@ func (p *Prover) onBlockProposed(
p.cancelProof(ctx, event.Meta.Id)
}

// check whether this prover has been chosen through PoS mechanism to prove the block
chosenProver, err := p.rpc.TaikoProverPoolL1.GetProver(nil, event.Id)
block, err := p.rpc.TaikoL1.GetBlock(nil, event.Id)
if err != nil {
return err
}

if chosenProver != p.proverAddress {
log.Info("proposed block not proveable", "blockID", event.Id, "prover", chosenProver.Hex())
if block.AssignedProver != p.proverAddress {
log.Info("proposed block not proveable", "blockID", event.Id, "prover", block.AssignedProver.Hex())
return nil
}

Expand Down Expand Up @@ -605,7 +603,7 @@ func (p *Prover) checkChainVerification(lastLatestVerifiedL1Height uint64) error
log.Warn(
"No new block verification in `proofCooldownPeriod * 2` seconeds",
"latestVerifiedL1Height", p.latestVerifiedL1Height,
"proofCooldownPeriod", p.protocolConfigs.ProofCooldownPeriod,
"proofCooldownPeriod", p.protocolConfigs.ProofRegularCooldown,
)

stateVar, err := p.rpc.TaikoL1.GetStateVariables(nil)
Expand Down
6 changes: 2 additions & 4 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func (s *ProverTestSuite) TestOnBlockProposed() {
// Valid block
e := testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.proposer, s.d.ChainSyncer().CalldataSyncer())
s.Nil(s.p.onBlockProposed(context.Background(), e, func() {}))
// TODO: uncomment once the protocol code has the ability to actually select a prover
//s.Nil(s.p.validProofSubmitter.SubmitProof(context.Background(), <-s.p.proofGenerationCh))
s.Nil(s.p.validProofSubmitter.SubmitProof(context.Background(), <-s.p.proofGenerationCh))

// Empty blocks
for _, e = range testutils.ProposeAndInsertEmptyBlocks(
Expand All @@ -113,8 +112,7 @@ func (s *ProverTestSuite) TestOnBlockProposed() {
) {
s.Nil(s.p.onBlockProposed(context.Background(), e, func() {}))

// TODO: uncomment once the protocol code has the ability to actually select a prover
//s.Nil(s.p.validProofSubmitter.SubmitProof(context.Background(), <-s.p.proofGenerationCh))
s.Nil(s.p.validProofSubmitter.SubmitProof(context.Background(), <-s.p.proofGenerationCh))
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cat ${TAIKO_MONO_DIR}/packages/protocol/out/TaikoL2.sol/TaikoL2.json |
jq .abi |
${ABIGEN_BIN} --abi - --type TaikoL2Client --pkg bindings --out $DIR/../bindings/gen_taiko_l2.go

cat ${TAIKO_MONO_DIR}/packages/protocol/out/StakingProverPool.sol/StakingProverPool.json |
cat ${TAIKO_MONO_DIR}/packages/protocol/out/ProverPool.sol/ProverPool.json |
jq .abi |
${ABIGEN_BIN} --abi - --type TaikoL1ProverPool --pkg bindings --out $DIR/../bindings/gen_taiko_prover_pool_l1.go

Expand Down
42 changes: 30 additions & 12 deletions testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testutils
import (
"context"
"crypto/ecdsa"
"fmt"
"math"
"math/big"
"os"
Expand Down Expand Up @@ -92,26 +93,43 @@ func (s *ClientTestSuite) SetupTest() {
proverOpts, err := bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, rpcCli.L1ChainID)
s.Nil(err)

minTkoAmount, err := s.RpcClient.TaikoProverPoolL1.MINTKOAMOUNT(nil)
balance, err := s.RpcClient.TaikoTokenL1.BalanceOf(nil, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey))
s.Nil(err)

amt := new(big.Int).Add(minTkoAmount, big.NewInt(1))
fmt.Println("prover balance", "balance", balance.String())

// proposer has tKO, need to transfer to prover
_, err = s.RpcClient.TaikoTokenL1.Transfer(proposerOpts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), amt)
proverInfo, err := s.RpcClient.TaikoProverPoolL1.GetStaker(nil, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey))
s.Nil(err)

prover, err := s.RpcClient.TaikoProverPoolL1.Provers(nil, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey))
s.Nil(err)
log.Info("proverInfo", "proverId", proverInfo.Staker.ProverId, "capacity", proverInfo.Staker.MaxCapacity)

if proverInfo.Staker.ProverId == 0 {

minStakePerCapacity, err := s.RpcClient.TaikoProverPoolL1.MINSTAKEPERCAPACITY(nil)
s.Nil(err)

capacity, err := s.RpcClient.TaikoProverPoolL1.MAXCAPACITYLOWERBOUND(nil)
s.Nil(err)
amt := new(big.Int).Mul(big.NewInt(int64(minStakePerCapacity)), big.NewInt(int64(capacity)))

oneTko, err := s.RpcClient.TaikoProverPoolL1.ONETKO(nil)
s.Nil(err)

amtTko := new(big.Int).Mul(amt, new(big.Int).SetInt64(int64(oneTko)))

log.Info("amt to stake", "amt", amtTko)

// proposer has tKO, need to transfer to prover
_, err = s.RpcClient.TaikoTokenL1.Transfer(proposerOpts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), amtTko)
s.Nil(err)

if prover.ProverAddress != crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey) {
minFeeMultiplier, err := s.RpcClient.TaikoProverPoolL1.MINMULTIPLIER(nil)
rewardPerGas := 1
s.Nil(err)
_, err = s.RpcClient.TaikoProverPoolL1.EnterProverPool(
_, err = s.RpcClient.TaikoProverPoolL1.Stake(
proverOpts,
amt,
new(big.Int).SetUint64(uint64(minFeeMultiplier)),
32,
uint32(amt.Uint64()),
uint16(rewardPerGas),
uint16(capacity),
)
s.Nil(err)
}
Expand Down

0 comments on commit 57e127b

Please sign in to comment.