Skip to content

Commit

Permalink
Use BoLD contracts to test delay buffer
Browse files Browse the repository at this point in the history
Rebase the delay buffer PR on top of BoLD's little merge. Then, use the
BoLD version of the contracts when appropriate instead of using the
delay-buffer development branch.
  • Loading branch information
gligneul committed Oct 28, 2024
1 parent fb86fad commit b0d586c
Show file tree
Hide file tree
Showing 9 changed files with 509 additions and 97 deletions.
3 changes: 1 addition & 2 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"

"github.com/offchainlabs/bold/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/arbnode/redislock"
Expand All @@ -44,7 +45,6 @@ import (
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/util"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/blobs"
Expand Down Expand Up @@ -317,7 +317,6 @@ func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, e
if err = opts.Config().Validate(); err != nil {
return nil, err
}
// TODO(delaybuffer) use new bridgegen
seqInboxABI, err := bridgegen.SequencerInboxMetaData.GetAbi()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion arbnode/delay_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/offchainlabs/bold/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/util/headerreader"
)

Expand Down
37 changes: 0 additions & 37 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker"
boldstaker "github.com/offchainlabs/nitro/staker/bold"
legacystaker "github.com/offchainlabs/nitro/staker/legacy"
Expand All @@ -53,42 +52,6 @@ import (
"github.com/offchainlabs/nitro/wsbroadcastserver"
)

func DefaultBufferConfig() rollupgen.BufferConfig {
return rollupgen.BufferConfig{
Threshold: 600, // 1 hour of blocks
Max: 14400, // 2 days of blocks
ReplenishRateInBasis: 500, // 5%
}
}

func GenerateRollupConfig(prod bool, wasmModuleRoot common.Hash, rollupOwner common.Address, chainConfig *params.ChainConfig, serializedChainConfig []byte, loserStakeEscrow common.Address, bufferConfig rollupgen.BufferConfig) rollupgen.Config {
var confirmPeriod uint64
if prod {
confirmPeriod = 45818
} else {
confirmPeriod = 20
}
return rollupgen.Config{
ConfirmPeriodBlocks: confirmPeriod,
ExtraChallengeTimeBlocks: 200,
StakeToken: common.Address{},
BaseStake: big.NewInt(params.Ether),
WasmModuleRoot: wasmModuleRoot,
Owner: rollupOwner,
LoserStakeEscrow: loserStakeEscrow,
ChainId: chainConfig.ChainID,
// TODO could the ChainConfig be just []byte?
ChainConfig: string(serializedChainConfig),
SequencerInboxMaxTimeVariation: rollupgen.ISequencerInboxMaxTimeVariation{
DelayBlocks: big.NewInt(60 * 60 * 24 / 15),
FutureBlocks: big.NewInt(12),
DelaySeconds: big.NewInt(60 * 60 * 24),
FutureSeconds: big.NewInt(60 * 60),
},
BufferConfig: bufferConfig,
}
}

type Config struct {
Sequencer bool `koanf:"sequencer"`
ParentChainReader headerreader.Config `koanf:"parent-chain-reader" reload:"hot"`
Expand Down
12 changes: 2 additions & 10 deletions cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/validator/server_common"

Expand All @@ -26,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/offchainlabs/nitro/arbnode"
"github.com/offchainlabs/nitro/cmd/util"
deploycode "github.com/offchainlabs/nitro/deploy"
)
Expand Down Expand Up @@ -62,7 +60,6 @@ func main() {
authorizevalidators := flag.Uint64("authorizevalidators", 0, "Number of validators to preemptively authorize")
txTimeout := flag.Duration("txtimeout", 10*time.Minute, "Timeout when waiting for a transaction to be included in a block")
prod := flag.Bool("prod", false, "Whether to configure the rollup for production or testing")
isDelayBufferable := flag.Bool("delayBufferable", false, "Whether the sequencer-inbox delay buffer is enabled")
flag.Parse()
l1ChainId := new(big.Int).SetUint64(*l1ChainIdUint)
maxDataSize := new(big.Int).SetUint64(*maxDataSizeUint)
Expand Down Expand Up @@ -172,11 +169,6 @@ func main() {
panic(fmt.Errorf("failed to deserialize chain config: %w", err))
}

var bufferConfig rollupgen.BufferConfig
if *isDelayBufferable {
bufferConfig = arbnode.DefaultBufferConfig()
}

arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err := headerreader.New(ctx, l1client, func() *headerreader.Config { return &headerReaderConfig }, arbSys)
if err != nil {
Expand All @@ -186,14 +178,14 @@ func main() {
defer l1Reader.StopAndWait()

nativeToken := common.HexToAddress(*nativeTokenAddressString)
deployedAddresses, err := deploycode.DeployOnParentChain(
deployedAddresses, err := deploycode.DeployLegacyOnParentChain(
ctx,
l1Reader,
l1TransactionOpts,
batchPosters,
batchPosterManagerAddress,
*authorizevalidators,
arbnode.GenerateRollupConfig(*prod, moduleRoot, ownerAddress, &chainConfig, chainConfigJson, loserEscrowAddress, bufferConfig),
deploycode.GenerateLegacyRollupConfig(*prod, moduleRoot, ownerAddress, &chainConfig, chainConfigJson, loserEscrowAddress),
nativeToken,
maxDataSize,
true,
Expand Down
117 changes: 91 additions & 26 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,89 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/offchainlabs/bold/solgen/go/bridgegen"
"github.com/offchainlabs/bold/solgen/go/challengeV2gen"
"github.com/offchainlabs/bold/solgen/go/ospgen"
"github.com/offchainlabs/bold/solgen/go/rollupgen"
"github.com/offchainlabs/bold/solgen/go/yulgen"
"github.com/offchainlabs/nitro/cmd/chaininfo"
"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/rollupgen"
"github.com/offchainlabs/nitro/solgen/go/upgrade_executorgen"
"github.com/offchainlabs/nitro/solgen/go/yulgen"
"github.com/offchainlabs/nitro/util/headerreader"
)

// lint:require-exhaustive-initialization
type RollupConfigOpts struct {
Prod bool
WasmModuleRoot common.Hash
RollupOwner common.Address
ChainConfig *params.ChainConfig
SerializedChainConfig []byte
LoserStakeEscrow common.Address
MiniStakeValues []*big.Int
StakeToken common.Address
GenesisExecutionState rollupgen.AssertionState
GenesisInboxCount *big.Int
AnyTrustFastConfirmer common.Address
LayerZeroBlockEdgeHeight uint64
LayerZeroBigStepEdgeHeight uint64
LayerZeroSmallStepEdgeHeight uint64
NumBigStepLevel uint8
BufferConfig rollupgen.BufferConfig
}

func DefaultBufferConfig() rollupgen.BufferConfig {
return rollupgen.BufferConfig{
Threshold: 600, // 1 hour of blocks
Max: 14400, // 2 days of blocks
ReplenishRateInBasis: 500, // 5%
}
}

func GenerateRollupConfig(opts *RollupConfigOpts) rollupgen.Config {
var confirmPeriod uint64
if opts.Prod {
confirmPeriod = 45818
} else {
confirmPeriod = 25
}

var gracePeriod uint64
if opts.Prod {
gracePeriod = 14400
} else {
gracePeriod = 3
}

cfg := rollupgen.Config{
ConfirmPeriodBlocks: confirmPeriod,
StakeToken: opts.StakeToken,
BaseStake: big.NewInt(1),
WasmModuleRoot: opts.WasmModuleRoot,
Owner: opts.RollupOwner,
LoserStakeEscrow: opts.LoserStakeEscrow,
ChainId: opts.ChainConfig.ChainID,
ChainConfig: string(opts.SerializedChainConfig),
MiniStakeValues: opts.MiniStakeValues,
SequencerInboxMaxTimeVariation: rollupgen.ISequencerInboxMaxTimeVariation{
DelayBlocks: big.NewInt(60 * 60 * 24 / 15),
FutureBlocks: big.NewInt(12),
DelaySeconds: big.NewInt(60 * 60 * 24),
FutureSeconds: big.NewInt(60 * 60),
},
LayerZeroBlockEdgeHeight: new(big.Int).SetUint64(opts.LayerZeroBlockEdgeHeight),
LayerZeroBigStepEdgeHeight: new(big.Int).SetUint64(opts.LayerZeroBigStepEdgeHeight),
LayerZeroSmallStepEdgeHeight: new(big.Int).SetUint64(opts.LayerZeroSmallStepEdgeHeight),
GenesisAssertionState: opts.GenesisExecutionState,
GenesisInboxCount: opts.GenesisInboxCount,
AnyTrustFastConfirmer: opts.AnyTrustFastConfirmer,
NumBigStepLevel: opts.NumBigStepLevel,
ChallengeGracePeriodBlocks: gracePeriod,
BufferConfig: opts.BufferConfig,
}
return cfg
}

func andTxSucceeded(ctx context.Context, parentChainReader *headerreader.HeaderReader, tx *types.Transaction, err error) error {
if err != nil {
return fmt.Errorf("error submitting tx: %w", err)
Expand Down Expand Up @@ -167,7 +240,7 @@ func deployChallengeFactory(ctx context.Context, parentChainReader *headerreader
return common.Address{}, common.Address{}, fmt.Errorf("ospHostIo deploy error: %w", err)
}

challengeManagerAddr, tx, _, err := challengegen.DeployChallengeManager(auth, client)
challengeManagerAddr, tx, _, err := challengeV2gen.DeployEdgeChallengeManager(auth, client)
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return common.Address{}, common.Address{}, fmt.Errorf("challenge manager deploy error: %w", err)
Expand All @@ -182,57 +255,51 @@ func deployChallengeFactory(ctx context.Context, parentChainReader *headerreader
return ospEntryAddr, challengeManagerAddr, nil
}

func deployRollupCreator(ctx context.Context, parentChainReader *headerreader.HeaderReader, auth *bind.TransactOpts, maxDataSize *big.Int, chainSupportsBlobs bool) (*rollupgen.RollupCreator, common.Address, common.Address, common.Address, error) {
func deployRollupCreator(ctx context.Context, parentChainReader *headerreader.HeaderReader, auth *bind.TransactOpts, maxDataSize *big.Int, chainSupportsBlobs bool) (*rollupgen.RollupCreator, common.Address, common.Address, error) {
bridgeCreator, err := deployBridgeCreator(ctx, parentChainReader, auth, maxDataSize, chainSupportsBlobs)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("bridge creator deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("bridge creator deploy error: %w", err)
}

ospEntryAddr, challengeManagerAddr, err := deployChallengeFactory(ctx, parentChainReader, auth)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, err
return nil, common.Address{}, common.Address{}, err
}

rollupAdminLogic, tx, _, err := rollupgen.DeployRollupAdminLogic(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("rollup admin logic deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("rollup admin logic deploy error: %w", err)
}

rollupUserLogic, tx, _, err := rollupgen.DeployRollupUserLogic(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("rollup user logic deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("rollup user logic deploy error: %w", err)
}

rollupCreatorAddress, tx, rollupCreator, err := rollupgen.DeployRollupCreator(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("rollup creator deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("rollup creator deploy error: %w", err)
}

upgradeExecutor, tx, _, err := upgrade_executorgen.DeployUpgradeExecutor(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("upgrade executor deploy error: %w", err)
}

validatorUtils, tx, _, err := rollupgen.DeployValidatorUtils(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("validator utils deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("upgrade executor deploy error: %w", err)
}

validatorWalletCreator, tx, _, err := rollupgen.DeployValidatorWalletCreator(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("validator wallet creator deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("validator wallet creator deploy error: %w", err)
}

l2FactoriesDeployHelper, tx, _, err := rollupgen.DeployDeployHelper(auth, parentChainReader.Client())
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("deploy helper creator deploy error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("deploy helper creator deploy error: %w", err)
}

tx, err = rollupCreator.SetTemplates(
Expand All @@ -243,24 +310,23 @@ func deployRollupCreator(ctx context.Context, parentChainReader *headerreader.He
rollupAdminLogic,
rollupUserLogic,
upgradeExecutor,
validatorUtils,
validatorWalletCreator,
l2FactoriesDeployHelper,
)
err = andTxSucceeded(ctx, parentChainReader, tx, err)
if err != nil {
return nil, common.Address{}, common.Address{}, common.Address{}, fmt.Errorf("rollup set template error: %w", err)
return nil, common.Address{}, common.Address{}, fmt.Errorf("rollup set template error: %w", err)
}

return rollupCreator, rollupCreatorAddress, validatorUtils, validatorWalletCreator, nil
return rollupCreator, rollupCreatorAddress, validatorWalletCreator, nil
}

func DeployOnParentChain(ctx context.Context, parentChainReader *headerreader.HeaderReader, deployAuth *bind.TransactOpts, batchPosters []common.Address, batchPosterManager common.Address, authorizeValidators uint64, config rollupgen.Config, nativeToken common.Address, maxDataSize *big.Int, chainSupportsBlobs bool) (*chaininfo.RollupAddresses, error) {
if config.WasmModuleRoot == (common.Hash{}) {
return nil, errors.New("no machine specified")
}

rollupCreator, _, validatorUtils, validatorWalletCreator, err := deployRollupCreator(ctx, parentChainReader, deployAuth, maxDataSize, chainSupportsBlobs)
rollupCreator, _, validatorWalletCreator, err := deployRollupCreator(ctx, parentChainReader, deployAuth, maxDataSize, chainSupportsBlobs)
if err != nil {
return nil, fmt.Errorf("error deploying rollup creator: %w", err)
}
Expand Down Expand Up @@ -305,7 +371,6 @@ func DeployOnParentChain(ctx context.Context, parentChainReader *headerreader.He
Rollup: info.RollupAddress,
NativeToken: nativeToken,
UpgradeExecutor: info.UpgradeExecutor,
ValidatorUtils: validatorUtils,
ValidatorWalletCreator: validatorWalletCreator,
}, nil
}
Loading

0 comments on commit b0d586c

Please sign in to comment.