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

feat(batcher): send batcher transaction right before KromaMPTTime #393

Open
wants to merge 5 commits into
base: feat/separate-deposit-tx
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kroma-network/kroma
go 1.21

require (
github.com/btcsuite/btcd v0.24.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/cockroachdb/pebble v0.0.0-20231018212520-f6cde3fc2fa4
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
Expand Down Expand Up @@ -207,4 +207,4 @@ require (

replace github.com/ethereum-optimism/optimism v1.7.2 => ./

replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v0.5.0
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/kroma-network/go-ethereum v1.101308.3-0.20241108085945-79ec5dfd8be5
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBT
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.0 h1:gL3uHE/IaFj6fcZSu03SvqPMSx7s/dPzfpG/atRwWdo=
github.com/btcsuite/btcd v0.24.0/go.mod h1:K4IDc1593s8jKXIF7yS7yCTSxrknB9z0STzc2j6XgE4=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
Expand Down Expand Up @@ -395,8 +395,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kroma-network/go-ethereum v0.5.0 h1:HqQ7khCuhQSWFCJu6/WnRQaBFlwDpPNNaLqDI3e+Br4=
github.com/kroma-network/go-ethereum v0.5.0/go.mod h1:SEk7AN/4FrDNJZg2pE1ja6xtPxLIJjfsbVVTweOafyk=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241108085945-79ec5dfd8be5 h1:SKBXidreKLNJCV5cPD5Tefd0Iu1N8si3TXThr82rXO0=
github.com/kroma-network/go-ethereum v1.101308.3-0.20241108085945-79ec5dfd8be5/go.mod h1:ZG4M8oph2j0C+R6CtUXuHeeUk5TuN5hVyl9gfwZawJg=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84 h1:VpLCQx+tFV6Nk0hbs3Noyxma/q9wIDdyacKpGQWUMI8=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84/go.mod h1:w54LrYo5rJEV503BgMPRNONsLTOEQv5V87q+uYaw9sM=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
10 changes: 4 additions & 6 deletions kroma-chain-ops/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
ShanghaiTime: config.CanyonTime(block.Time()),
CancunTime: config.EcotoneTime(block.Time()),
EcotoneTime: config.EcotoneTime(block.Time()),
// TODO(seolaoh): uncomment this when geth updated
// KromaMPTTime: config.KromaMPTTime(block.Time()),
KromaMPTTime: config.KromaMPTTime(block.Time()),
InteropTime: config.InteropTime(block.Time()),
Kroma: &params.KromaConfig{
EIP1559Denominator: eip1559Denom,
Expand All @@ -73,10 +72,9 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
Zktrie: true,
}

// TODO(seolaoh): turn off Zktrie when MPT time is past in genesis
//if kromaChainConfig.IsKromaMPT(block.Time()) {
// kromaChainConfig.Zktrie = false
//}
if kromaChainConfig.IsKromaMPT(block.Time()) {
kromaChainConfig.Zktrie = false
}

gasLimit := config.L2GenesisBlockGasLimit
if gasLimit == 0 {
Expand Down
6 changes: 6 additions & 0 deletions op-batcher/batcher/channel_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var (
ErrChannelTimeoutClose = errors.New("close to channel timeout")
ErrSeqWindowClose = errors.New("close to sequencer window timeout")
ErrTerminated = errors.New("channel terminated")
// [Kroma: START]
ErrJustBeforeKromaMPTTime = errors.New("reached the block just before KromaMPTTime")
// [Kroma: END]
)

type ChannelFullError struct {
Expand Down Expand Up @@ -174,7 +177,10 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro
if err = c.co.FullErr(); err != nil {
c.setFullErr(err)
// Adding this block still worked, so don't return error, just mark as full
} else /* [Kroma: START] */ if c.rollupCfg.KromaMPTTime != nil && block.Time() == *c.rollupCfg.KromaMPTTime-c.rollupCfg.BlockTime {
c.setFullErr(ErrJustBeforeKromaMPTTime)
}
// [Kroma: END]

return l1info, nil
}
Expand Down
65 changes: 65 additions & 0 deletions op-batcher/batcher/channel_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,68 @@ func TestChannelManager_ChannelCreation(t *testing.T) {
})
}
}

// [Kroma: START]
func TestChannelManager_Close_BeforeMPTBlock(t *testing.T) {
require := require.New(t)

rng := rand.New(rand.NewSource(123))
log := testlog.Logger(t, log.LevelError)

cfg := defaultTestChannelConfig()
cfg.InitNoneCompressor()
cfg.BatchType = derive.SpanBatchType
rollupConfig := defaultTestRollupConfig
rollupConfig.BlockTime = 2
kromaMPTTime := uint64(1732200100)
rollupConfig.KromaMPTTime = &kromaMPTTime
m := NewChannelManager(log, metrics.NoopMetrics, cfg, &rollupConfig)
m.Clear(eth.BlockID{})

numTx := 1
zktBlock1 := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)
zktBlock2 := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)
mptBlock := derivetest.RandomL2BlockWithChainId(rng, numTx, defaultTestRollupConfig.L2ChainID)

h := zktBlock1.Header()
h.Time = kromaMPTTime - rollupConfig.BlockTime*2
zktBlock1 = zktBlock1.WithSeal(h)

h = zktBlock2.Header()
h.Number = new(big.Int).Add(zktBlock1.Number(), big.NewInt(1))
h.Time = zktBlock1.Time() + rollupConfig.BlockTime
h.ParentHash = zktBlock1.Hash()
zktBlock2 = zktBlock2.WithSeal(h)

h = mptBlock.Header()
h.Number = new(big.Int).Add(zktBlock2.Number(), big.NewInt(1))
h.Time = zktBlock2.Time() + rollupConfig.BlockTime
h.ParentHash = zktBlock2.Hash()
mptBlock = mptBlock.WithSeal(h)

require.NoError(m.AddL2Block(zktBlock1), "adding 1st L2 block")
require.NoError(m.AddL2Block(zktBlock2), "adding 2nd L2 block")
require.NoError(m.AddL2Block(mptBlock), "adding 3nd L2 block")

txdata, err := m.TxData(eth.BlockID{})
require.NoError(err)
ch1 := m.txChannels[txdata.ID().String()]
require.ErrorIs(ch1.FullErr(), ErrJustBeforeKromaMPTTime)

// current channel is not full yet
_, err = m.TxData(eth.BlockID{})
require.ErrorIs(err, io.EOF)

// Close immediately marks the channel as full with an ErrTerminated
// if the channel is not already full.
m.currentChannel.Close()
err = m.outputFrames()
require.NoError(err)
txdata, err = m.TxData(eth.BlockID{})
require.NoError(err)
ch2 := m.txChannels[txdata.ID().String()]
require.ErrorIs(ch2.FullErr(), ErrTerminated)
require.NotEqual(ch1.ID(), ch2.ID())
}

// [Kroma: END]
12 changes: 12 additions & 0 deletions op-e2e/actions/ecotone_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
// See [derive.EcotoneNetworkUpgradeTransactions]
require.Equal(t, 7, len(transactions))

// [Kroma: START] Use KromaDepositTx instead of DepositTx
for i, otx := range transactions {
if otx.Type() == types.DepositTxType {
b, err := otx.MarshalBinary()
require.NoError(gt, err)
kromaDep, err := derive.ToKromaDepositBytes(b)
require.NoError(gt, err)
transactions[i].UnmarshalBinary(kromaDep)
}
}
// [Kroma: END]

l1Info, err := derive.L1BlockInfoFromBytes(sd.RollupCfg, latestBlock.Time(), transactions[0].Data())
require.NoError(t, err)
require.Equal(t, derive.L1InfoBedrockLen, len(transactions[0].Data()))
Expand Down
9 changes: 5 additions & 4 deletions op-e2e/actions/l2_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"math/big"
"testing"

"github.com/ethereum-optimism/optimism/op-service/client/l2/engineapi"
"github.com/ethereum-optimism/optimism/op-service/client/l2/engineapi/test"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand All @@ -19,6 +17,9 @@ import (
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-service/client/l2/engineapi"
"github.com/ethereum-optimism/optimism/op-service/client/l2/engineapi/test"

"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources"
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestL2EngineAPI(gt *testing.T) {
chainA, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(i int, gen *core.BlockGen) {
gen.SetCoinbase(common.Address{'A'})
})
payloadA, err := eth.BlockAsPayload(chainA[0], sd.RollupCfg.CanyonTime)
payloadA, err := eth.BlockAsPayload(chainA[0], sd.RollupCfg.CanyonTime, sd.RollupCfg.KromaMPTTime)
require.NoError(t, err)

// apply the payload
Expand All @@ -69,7 +70,7 @@ func TestL2EngineAPI(gt *testing.T) {
chainB, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(i int, gen *core.BlockGen) {
gen.SetCoinbase(common.Address{'B'})
})
payloadB, err := eth.BlockAsPayload(chainB[0], sd.RollupCfg.CanyonTime)
payloadB, err := eth.BlockAsPayload(chainB[0], sd.RollupCfg.CanyonTime, sd.RollupCfg.KromaMPTTime)
require.NoError(t, err)

// apply the payload
Expand Down
14 changes: 14 additions & 0 deletions op-e2e/actions/l2_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,27 @@ func (s *L2Verifier) ActL2PipelineFull(t Testing) {
// ActL2UnsafeGossipReceive creates an action that can receive an unsafe execution payload, like gossipsub
func (s *L2Verifier) ActL2UnsafeGossipReceive(payload *eth.ExecutionPayloadEnvelope) Action {
return func(t Testing) {
// [Kroma: START] Use KromaDepositTx instead of DepositTx
for i, otx := range payload.ExecutionPayload.Transactions {
var err error
payload.ExecutionPayload.Transactions[i], err = derive.ToKromaDepositBytes(otx)
require.NoError(t, err)
}
// [Kroma: END]
s.derivation.AddUnsafePayload(payload)
}
}

// ActL2InsertUnsafePayload creates an action that can insert an unsafe execution payload
func (s *L2Verifier) ActL2InsertUnsafePayload(payload *eth.ExecutionPayloadEnvelope) Action {
return func(t Testing) {
// [Kroma: START] Use KromaDepositTx instead of DepositTx
for i, otx := range payload.ExecutionPayload.Transactions {
var err error
payload.ExecutionPayload.Transactions[i], err = derive.ToKromaDepositBytes(otx)
require.NoError(t, err)
}
// [Kroma: END]
ref, err := derive.PayloadToBlockRef(s.rollupCfg, payload.ExecutionPayload)
require.NoError(t, err)
err = s.engine.InsertUnsafePayload(t.Ctx(), payload, ref)
Expand Down
12 changes: 11 additions & 1 deletion op-e2e/actions/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,17 @@ func (s *CrossLayerUser) CheckDepositTx(t Testing, l1TxHash common.Hash, index i
require.Less(t, index, len(depositReceipt.Logs), "must have enough logs in receipt")
reconstructedDep, err := derive.UnmarshalDepositLogEvent(depositReceipt.Logs[index])
require.NoError(t, err, "Could not reconstruct L2 Deposit")
l2Tx := types.NewTx(reconstructedDep)
// [Kroma: START] Use KromaDepositTx instead of DepositTx
l2Tx := types.NewTx(&types.KromaDepositTx{
SourceHash: reconstructedDep.SourceHash,
From: reconstructedDep.From,
To: reconstructedDep.To,
Mint: reconstructedDep.Mint,
Value: reconstructedDep.Value,
Gas: reconstructedDep.Gas,
Data: reconstructedDep.Data,
})
// [Kroma: END]
s.L2.CheckReceipt(t, l2Success, l2Tx.Hash())
}
}
Expand Down
16 changes: 3 additions & 13 deletions op-e2e/actions/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"math/rand"
"testing"

"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-service/testlog"
)

type hardforkScheduledTest struct {
regolithTime *hexutil.Uint64
canyonTime *hexutil.Uint64
deltaTime *hexutil.Uint64
ecotoneTime *hexutil.Uint64
kromaMPTTime *hexutil.Uint64
fjordTime *hexutil.Uint64
runToFork string
}
Expand All @@ -35,8 +35,6 @@ func (tc *hardforkScheduledTest) fork(fork string) **hexutil.Uint64 {
switch fork {
case "fjord":
return &tc.fjordTime
case "mpt":
return &tc.kromaMPTTime
case "ecotone":
return &tc.ecotoneTime
case "delta":
Expand Down Expand Up @@ -67,10 +65,6 @@ func TestCrossLayerUser(t *testing.T) {
"canyon",
"delta",
"ecotone",
// [Kroma: START]
// TODO(seolaoh): uncomment below forks when geth updated
//"mpt",
// [Kroma: END]
//"fjord",
}
for i, fork := range forks {
Expand Down Expand Up @@ -119,7 +113,6 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
dp.DeployConfig.L2GenesisCanyonTimeOffset = test.canyonTime
dp.DeployConfig.L2GenesisDeltaTimeOffset = test.deltaTime
dp.DeployConfig.L2GenesisEcotoneTimeOffset = test.ecotoneTime
dp.DeployConfig.L2GenesisKromaMPTTimeOffset = test.kromaMPTTime
dp.DeployConfig.L2GenesisFjordTimeOffset = test.fjordTime

// [Kroma: START]
Expand All @@ -133,9 +126,6 @@ func runCrossLayerUserTest(gt *testing.T, test hardforkScheduledTest) {
if test.ecotoneTime != nil {
require.Zero(t, uint64(*test.ecotoneTime)%uint64(dp.DeployConfig.L2BlockTime), "ecotone fork must be aligned")
}
if test.kromaMPTTime != nil {
require.Zero(t, uint64(*test.kromaMPTTime)%uint64(dp.DeployConfig.L2BlockTime), "kroma mpt fork must be aligned")
}

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand Down
5 changes: 4 additions & 1 deletion op-e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func TestERC20BridgeDeposits(t *testing.T) {

depositTx, err := derive.UnmarshalDepositLogEvent(&depositEvent.Raw)
require.NoError(t, err)
_, err = wait.ForReceiptOK(context.Background(), l2Client, types.NewTx(depositTx).Hash())
// [Kroma: START] Use KromaDepositTx instead of DepositTx
kromaDepTx := types.NewTx(depositTx).ToKromaDepositTx()
_, err = wait.ForReceiptOK(context.Background(), l2Client, kromaDepTx.Hash())
// [Kroma: END]
require.NoError(t, err)

// Ensure that the deposit went through
Expand Down
Loading