Skip to content

Commit

Permalink
fix: remove unnecessary KromaDepositTx conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangssu committed Dec 5, 2024
1 parent 2a89698 commit 504c0e0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
6 changes: 6 additions & 0 deletions op-e2e/op_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ func (d *OpGeth) CreatePayloadAttributes(txs ...*types.Transaction) (*eth.Payloa
if err != nil {
return nil, err
}
if d.L2ChainConfig.IsPreKromaMPT(uint64(timestamp)) {
l1Info, err = derive.ToKromaDepositBytes(l1Info)
if err != nil {
return nil, err
}
}

var txBytes []hexutil.Bytes
txBytes = append(txBytes, l1Info)
Expand Down
16 changes: 0 additions & 16 deletions op-node/p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import (

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

"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/kroma-network/kroma/op-node/rollup/derive"
)

// StreamCtxFn provides a new context to use when handling stream requests
Expand Down Expand Up @@ -670,20 +668,6 @@ func (s *SyncClient) readExecutionPayload(data []byte, expectedTime uint64) (*et
return nil, fmt.Errorf("failed to decode response: %w", err)
}

// [Kroma: START] Use KromaDepositTx instead of DepositTx before MPT time
if !s.cfg.IsKromaMPT(expectedTime) {
for i, otx := range res.Transactions {
if otx[0] == types.DepositTxType {
var err error
res.Transactions[i], err = derive.ToKromaDepositBytes(otx)
if err != nil {
return nil, fmt.Errorf("failed to convert deposit tx to KromaDepositTx: %w", err)
}
}
}
}
// [Kroma: END]

return &eth.ExecutionPayloadEnvelope{ExecutionPayload: &res}, nil
}

Expand Down
7 changes: 0 additions & 7 deletions op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ func ToKromaDepositBytes(input hexutil.Bytes) (hexutil.Bytes, error) {
if input[0] != types.DepositTxType {
return nil, fmt.Errorf("unexpected transaction type: %d", input[0])
}
isKromaDepTx, err := types.IsKromaDepositTx(input[1:]);
if err != nil {
return nil, err
}
if isKromaDepTx {
return input, nil
}
var tx types.Transaction
if err := tx.UnmarshalBinary(input); err != nil {
return nil, fmt.Errorf("failed to decode deposit tx: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func TestAttributesQueue(t *testing.T) {
l1InfoTx, err := L1InfoDepositBytes(&rollupCfg, expectedL1Cfg, safeHead.SequenceNumber+1, l1Info, 0)
require.NoError(st, err)

l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
kromaDepTx, err := ToKromaDepositBytes(l1InfoTx)
require.NoError(st, err)
testAttributes(l1InfoTx, common.Address{})
testAttributes(kromaDepTx, common.Address{})
})

t.Run("after kroma mpt time", func(st *testing.T) {
Expand Down
70 changes: 70 additions & 0 deletions op-node/rollup/derive/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func TestPreparePayloadAttributes(t *testing.T) {
l1Info.InfoNum = l2Parent.L1Origin.Number + 1
epoch := l1Info.ID()
l1InfoTx, err := L1InfoDepositBytes(cfg, testSysCfg, 0, l1Info, 0)
// [Kroma: START] Use KromaDepositTx instead of DepositTx
l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
require.NoError(t, err)
// [Kroma: END]
require.NoError(t, err)
l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil)
attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher)
Expand Down Expand Up @@ -185,6 +189,10 @@ func TestPreparePayloadAttributes(t *testing.T) {

epoch := l1Info.ID()
l1InfoTx, err := L1InfoDepositBytes(cfg, testSysCfg, l2Parent.SequenceNumber+1, l1Info, 0)
// [Kroma: START] Use KromaDepositTx instead of DepositTx
l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
require.NoError(t, err)
// [Kroma: END]
require.NoError(t, err)

l1Fetcher.ExpectInfoByHash(epoch.Hash, l1Info, nil)
Expand Down Expand Up @@ -241,6 +249,68 @@ func TestPreparePayloadAttributes(t *testing.T) {
time--
}
l1InfoTx, err := L1InfoDepositBytes(cfg, testSysCfg, 0, l1Info, time)
// [Kroma: START] Use KromaDepositTx instead of DepositTx
l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
require.NoError(t, err)
// [Kroma: END]
require.NoError(t, err)
l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil)
attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher)
attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch)
require.NoError(t, err)
require.Equal(t, l1InfoTx, []byte(attrs.Transactions[0]))
})
}
})
// Test that the payload attributes builder changes the deposit format based on L2-time-based regolith activation
t.Run("kroma_mpt", func(t *testing.T) {
testCases := []struct {
name string
l1Time uint64
l2ParentTime uint64
kromaMPTTime uint64
kromaMPT bool
}{
{"exactly", 900, 1000 - cfg.BlockTime, 1000, true},
{"almost", 900, 1000 - cfg.BlockTime - 1, 1000, false},
{"inactive", 700, 700, 1000, false},
{"l1 time before kroma_mpt", 1000, 1001, 1001, true},
{"l1 time way before kroma_mpt", 1000, 2000, 2000, true},
{"l1 time before kroma_mpt and l2 after", 1000, 3000, 2000, true},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfgCopy := *cfg // copy, we are making kromaMPT config modifications
cfg := &cfgCopy
rng := rand.New(rand.NewSource(1234))
l1Fetcher := &testutils.MockL1Source{}
defer l1Fetcher.AssertExpectations(t)
l2Parent := testutils.RandomL2BlockRef(rng)
cfg.KromaMPTTime = &tc.kromaMPTTime
l2Parent.Time = tc.l2ParentTime

l1CfgFetcher := &testutils.MockL2Client{}
l1CfgFetcher.ExpectSystemConfigByL2Hash(l2Parent.Hash, testSysCfg, nil)
defer l1CfgFetcher.AssertExpectations(t)

l1Info := testutils.RandomBlockInfo(rng)
l1Info.InfoParentHash = l2Parent.L1Origin.Hash
l1Info.InfoNum = l2Parent.L1Origin.Number + 1
l1Info.InfoTime = tc.l1Time

epoch := l1Info.ID()
time := tc.kromaMPTTime
if !tc.kromaMPT {
time--
}
l1InfoTx, err := L1InfoDepositBytes(cfg, testSysCfg, 0, l1Info, time)

// [Kroma: START] Use KromaDepositTx instead of DepositTx
if cfg.KromaMPTTime != nil && time < *cfg.KromaMPTTime {
l1InfoTx, err = ToKromaDepositBytes(l1InfoTx)
require.NoError(t, err)
}
// [Kroma: END]
require.NoError(t, err)
l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil)
attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher)
Expand Down
5 changes: 0 additions & 5 deletions op-node/rollup/derive/l1_block_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,5 @@ func L1InfoDepositBytes(rollupCfg *rollup.Config, sysCfg eth.SystemConfig, seqNu
if err != nil {
return nil, fmt.Errorf("failed to encode L1 info tx: %w", err)
}
// [Kroma: START] Use KromaDepositTx instead of DepositTx before MPT time
if !rollupCfg.IsKromaMPT(l2BlockTime) {
opaqueL1Tx, err = ToKromaDepositBytes(opaqueL1Tx)
}
// [Kroma: END]
return opaqueL1Tx, nil
}

0 comments on commit 504c0e0

Please sign in to comment.