Skip to content

Commit 63463aa

Browse files
committed
feat: optimize batch data size by emptying IBC update client msg data
1 parent b750c56 commit 63463aa

20 files changed

+1004
-261
lines changed

challenger/types/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (cfg Config) Validate() error {
113113

114114
func (cfg Config) L1NodeConfig() nodetypes.NodeConfig {
115115
nc := nodetypes.NodeConfig{
116+
ChainID: cfg.L1Node.ChainID,
116117
RPC: cfg.L1Node.RPCAddress,
117118
ProcessType: nodetypes.PROCESS_TYPE_DEFAULT,
118119
Bech32Prefix: cfg.L1Node.Bech32Prefix,
@@ -122,6 +123,7 @@ func (cfg Config) L1NodeConfig() nodetypes.NodeConfig {
122123

123124
func (cfg Config) L2NodeConfig() nodetypes.NodeConfig {
124125
nc := nodetypes.NodeConfig{
126+
ChainID: cfg.L2Node.ChainID,
125127
RPC: cfg.L2Node.RPCAddress,
126128
ProcessType: nodetypes.PROCESS_TYPE_DEFAULT,
127129
Bech32Prefix: cfg.L2Node.Bech32Prefix,

e2e/batch_reconstruction_test.go

Lines changed: 147 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
cmtypes "github.com/cometbft/cometbft/types"
1717
"github.com/cosmos/cosmos-proto/anyutil"
1818
gogoproto "github.com/cosmos/gogoproto/proto"
19+
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
20+
ibctmlightclients "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
1921
opchildv1 "github.com/initia-labs/OPinit/api/opinit/opchild/v1"
2022
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
2123
executortypes "github.com/initia-labs/opinit-bots/executor/types"
@@ -35,7 +37,7 @@ func TestBatchReconstructionTest(t *testing.T) {
3537
Gas: "auto",
3638
GasPrices: "0.025uinit",
3739
GasAdjustment: 1.2,
38-
TrustingPeriod: "168h",
40+
TrustingPeriod: "1h",
3941
NumValidators: 1,
4042
NumFullNodes: 0,
4143
}
@@ -49,7 +51,7 @@ func TestBatchReconstructionTest(t *testing.T) {
4951
Gas: "auto",
5052
GasPrices: "0.025umin",
5153
GasAdjustment: 1.2,
52-
TrustingPeriod: "168h",
54+
TrustingPeriod: "1h",
5355
NumValidators: 1,
5456
NumFullNodes: 0,
5557
}
@@ -65,7 +67,24 @@ func TestBatchReconstructionTest(t *testing.T) {
6567
cases := []struct {
6668
name string
6769
daChainConfig DAChainConfig
70+
relayerImpl ibc.RelayerImplementation
6871
}{
72+
{
73+
name: "initia with go relayer",
74+
daChainConfig: DAChainConfig{
75+
ChainConfig: *l1ChainConfig,
76+
ChainType: ophosttypes.BatchInfo_CHAIN_TYPE_INITIA,
77+
},
78+
relayerImpl: ibc.CosmosRly,
79+
},
80+
{
81+
name: "initia with hermes relayer",
82+
daChainConfig: DAChainConfig{
83+
ChainConfig: *l1ChainConfig,
84+
ChainType: ophosttypes.BatchInfo_CHAIN_TYPE_INITIA,
85+
},
86+
relayerImpl: ibc.Hermes,
87+
},
6988
{
7089
name: "celestia",
7190
daChainConfig: DAChainConfig{
@@ -78,27 +97,21 @@ func TestBatchReconstructionTest(t *testing.T) {
7897
Gas: "auto",
7998
GasPrices: "0.25utia",
8099
GasAdjustment: 1.5,
81-
TrustingPeriod: "168h",
100+
TrustingPeriod: "1h",
82101
NumValidators: 1,
83102
NumFullNodes: 0,
84103
},
85104
ChainType: ophosttypes.BatchInfo_CHAIN_TYPE_CELESTIA,
86105
},
87-
},
88-
{
89-
name: "initia",
90-
daChainConfig: DAChainConfig{
91-
ChainConfig: *l1ChainConfig,
92-
ChainType: ophosttypes.BatchInfo_CHAIN_TYPE_INITIA,
93-
},
106+
relayerImpl: ibc.CosmosRly,
94107
},
95108
}
96109

97110
for _, tc := range cases {
98111
t.Run(tc.name, func(t *testing.T) {
99112
ctx := context.Background()
100113

101-
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, &tc.daChainConfig, bridgeConfig)
114+
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, &tc.daChainConfig, bridgeConfig, tc.relayerImpl)
102115

103116
err := testutil.WaitForBlocks(ctx, 20, op.Initia, op.Minitia)
104117
require.NoError(t, err)
@@ -142,7 +155,7 @@ func TestBatchReconstructionTest(t *testing.T) {
142155
require.NoError(t, err)
143156
require.NotNil(t, block)
144157

145-
err = fillOracleData(ctx, block, op.Initia)
158+
err = fillData(ctx, block, op.Initia)
146159
require.NoError(t, err)
147160

148161
pbb, err := block.ToProto()
@@ -243,7 +256,7 @@ func BlockFromProtoWithNoValidation(bp *cmtproto.Block) (*cmtypes.Block, error)
243256
return b, nil
244257
}
245258

246-
func fillOracleData(ctx context.Context, block *cmtypes.Block, chain *L1Chain) error {
259+
func fillData(ctx context.Context, block *cmtypes.Block, chain *L1Chain) error {
247260
for i, txBytes := range block.Txs {
248261
var raw txv1beta1.TxRaw
249262
if err := proto.Unmarshal(txBytes, &raw); err != nil {
@@ -305,6 +318,91 @@ func fillOracleData(ctx context.Context, block *cmtypes.Block, chain *L1Chain) e
305318
if err != nil {
306319
return errors.Join(errors.New("failed to marshal oracle msg"), err)
307320
}
321+
case "/ibc.core.client.v1.MsgUpdateClient":
322+
updateClientMsg := new(ibcclienttypes.MsgUpdateClient)
323+
err := updateClientMsg.Unmarshal(anyMsg.Value)
324+
if err != nil {
325+
return err
326+
}
327+
328+
if updateClientMsg.ClientMessage.TypeUrl != "/ibc.lightclients.tendermint.v1.Header" {
329+
continue
330+
}
331+
332+
tmHeader := new(ibctmlightclients.Header)
333+
err = tmHeader.Unmarshal(updateClientMsg.ClientMessage.Value)
334+
if err != nil {
335+
return err
336+
}
337+
338+
// fill ValidatorSet
339+
height := tmHeader.SignedHeader.Commit.Height
340+
validators, err := getAllValidators(ctx, chain, height)
341+
if err != nil {
342+
return err
343+
}
344+
cmtValidators, _, err := toCmtProtoValidators(validators)
345+
if err != nil {
346+
return err
347+
}
348+
if tmHeader.ValidatorSet == nil {
349+
tmHeader.ValidatorSet = new(cmtproto.ValidatorSet)
350+
}
351+
tmHeader.ValidatorSet.Validators = cmtValidators
352+
for _, val := range cmtValidators {
353+
if bytes.Equal(val.Address, tmHeader.SignedHeader.Header.ProposerAddress) {
354+
tmHeader.ValidatorSet.Proposer = val
355+
}
356+
}
357+
358+
// fill TrustedValidators
359+
height = int64(tmHeader.TrustedHeight.RevisionHeight)
360+
validators, err = getAllValidators(ctx, chain, height)
361+
if err != nil {
362+
return err
363+
}
364+
cmtValidators, _, err = toCmtProtoValidators(validators)
365+
if err != nil {
366+
return err
367+
}
368+
blockHeader, err := chain.GetFullNode().Client.Header(ctx, &height)
369+
if err != nil {
370+
return err
371+
}
372+
if tmHeader.TrustedValidators == nil {
373+
tmHeader.TrustedValidators = new(cmtproto.ValidatorSet)
374+
}
375+
tmHeader.TrustedValidators.Validators = cmtValidators
376+
for _, val := range cmtValidators {
377+
if bytes.Equal(val.Address, blockHeader.Header.ProposerAddress.Bytes()) {
378+
tmHeader.TrustedValidators.Proposer = val
379+
}
380+
}
381+
382+
// fill commit signatures
383+
height = tmHeader.SignedHeader.Commit.Height + 1
384+
block, err := chain.GetFullNode().Client.Block(ctx, &height)
385+
if err != nil {
386+
return err
387+
}
388+
389+
for sigIndex, signature := range tmHeader.SignedHeader.Commit.Signatures {
390+
if len(signature.Signature) == 2 {
391+
// fill signature
392+
blockSigIndex := int(signature.Signature[0]) + int(signature.Signature[1])<<8
393+
tmHeader.SignedHeader.Commit.Signatures[sigIndex] = *block.Block.LastCommit.Signatures[blockSigIndex].ToProto()
394+
}
395+
}
396+
397+
updateClientMsg.ClientMessage.Value, err = tmHeader.Marshal()
398+
if err != nil {
399+
return errors.Join(errors.New("failed to marshal tm header"), err)
400+
}
401+
402+
anyMsg.Value, err = updateClientMsg.Marshal()
403+
if err != nil {
404+
return errors.Join(errors.New("failed to marshal update client msg"), err)
405+
}
308406
default:
309407
continue
310408
}
@@ -323,3 +421,39 @@ func fillOracleData(ctx context.Context, block *cmtypes.Block, chain *L1Chain) e
323421
}
324422
return nil
325423
}
424+
425+
func getAllValidators(ctx context.Context, chain *L1Chain, height int64) ([]*cmtypes.Validator, error) {
426+
page := 1
427+
perPage := 100
428+
429+
validators := make([]*cmtypes.Validator, 0)
430+
for {
431+
result, err := chain.GetFullNode().Client.Validators(ctx, &height, &page, &perPage)
432+
if err != nil {
433+
return nil, err
434+
}
435+
validators = append(validators, result.Validators...)
436+
page++
437+
if len(validators) >= result.Total {
438+
break
439+
}
440+
}
441+
return validators, nil
442+
}
443+
444+
func toCmtProtoValidators(validators []*cmtypes.Validator) ([]*cmtproto.Validator, int64, error) {
445+
protoValidators := make([]*cmtproto.Validator, 0, len(validators))
446+
totalVotingPower := int64(0)
447+
448+
for i := range validators {
449+
protoValidator, err := validators[i].ToProto()
450+
if err != nil {
451+
return nil, 0, err
452+
}
453+
protoValidator.ProposerPriority = 0
454+
totalVotingPower += protoValidator.VotingPower
455+
456+
protoValidators = append(protoValidators, protoValidator)
457+
}
458+
return protoValidators, totalVotingPower, nil
459+
}

e2e/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func (op *DockerOPBot) pullContainerImageIfNecessary(containerImage ibc.DockerIm
494494
}
495495

496496
func (op *DockerOPBot) Name() string {
497-
return op.c.Name() + "-" + op.botName + "-" + dockerutil.SanitizeContainerName(op.testName)
497+
return dockerutil.CondenseHostName(dockerutil.SanitizeContainerName(op.c.Name() + "-" + op.botName + "-" + op.testName))
498498
}
499499

500500
func (op *DockerOPBot) Bind() []string {

e2e/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ require (
101101
github.com/cosmos/gogoproto v1.7.0
102102
github.com/cosmos/iavl v1.2.0 // indirect
103103
github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect
104-
github.com/cosmos/ibc-go/v8 v8.5.0 // indirect
104+
github.com/cosmos/ibc-go/v8 v8.5.0
105105
github.com/cosmos/ics23/go v0.11.0 // indirect
106106
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
107107
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect

e2e/helper.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"cosmossdk.io/math"
1414
"cosmossdk.io/x/feegrant"
1515
"github.com/avast/retry-go/v4"
16+
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
17+
ibctmlightclients "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
1618
"github.com/icza/dyno"
1719
oracleconfig "github.com/skip-mev/connect/v2/oracle/config"
1820
"github.com/skip-mev/connect/v2/providers/apis/marketmap"
@@ -118,6 +120,8 @@ func MinitiaEncoding() *cosmostestutil.TestEncodingConfig {
118120
cfg := cosmos.DefaultEncoding()
119121
authz.RegisterInterfaces(cfg.InterfaceRegistry)
120122
feegrant.RegisterInterfaces(cfg.InterfaceRegistry)
123+
ibcclienttypes.RegisterInterfaces(cfg.InterfaceRegistry)
124+
ibctmlightclients.RegisterInterfaces(cfg.InterfaceRegistry)
121125
opchildtypes.RegisterInterfaces(cfg.InterfaceRegistry)
122126
return &cfg
123127
}
@@ -130,6 +134,7 @@ func SetupTest(
130134
l2ChainConfig *ChainConfig,
131135
daChainConfig *DAChainConfig,
132136
bridgeConfig *BridgeConfig,
137+
relayerImpl ibc.RelayerImplementation,
133138
) OPTestHelper {
134139
require.NotNil(t, l1ChainConfig)
135140
require.NotNil(t, l2ChainConfig)
@@ -383,7 +388,7 @@ func SetupTest(
383388

384389
// relayer setup
385390

386-
relayer := interchaintest.NewBuiltinRelayerFactory(ibc.CosmosRly, zaptest.NewLogger(t)).Build(t, client, network)
391+
relayer := interchaintest.NewBuiltinRelayerFactory(relayerImpl, zaptest.NewLogger(t)).Build(t, client, network)
387392

388393
ic := interchaintest.NewInterchain().
389394
AddChain(initia).
@@ -394,6 +399,9 @@ func SetupTest(
394399
Chain2: minitia,
395400
Relayer: relayer,
396401
Path: ibcPath,
402+
CreateClientOpts: ibc.CreateClientOptions{
403+
TrustingPeriod: initia.Config().TrustingPeriod,
404+
},
397405
})
398406

399407
da := initia
@@ -496,7 +504,6 @@ func SetupTest(
496504
})
497505
err = op.WaitForSync(ctx)
498506
require.NoError(t, err)
499-
500507
return helper
501508
}
502509

@@ -558,7 +565,7 @@ func (op OPTestHelper) ExecutorConfig() *executortypes.Config {
558565
L1Node: executortypes.NodeConfig{
559566
ChainID: op.Initia.Config().ChainID,
560567
Bech32Prefix: op.Initia.Config().Bech32Prefix,
561-
RPCAddress: fmt.Sprintf("http://%s:26657", op.Initia.GetFullNode().Name()),
568+
RPCAddress: fmt.Sprintf("http://%s:26657", op.Initia.GetFullNode().HostName()),
562569
GasPrice: op.Initia.Config().GasPrices,
563570
GasAdjustment: op.Initia.Config().GasAdjustment,
564571
TxTimeout: 10,
@@ -567,7 +574,7 @@ func (op OPTestHelper) ExecutorConfig() *executortypes.Config {
567574
L2Node: executortypes.NodeConfig{
568575
ChainID: op.Minitia.Config().ChainID,
569576
Bech32Prefix: op.Minitia.Config().Bech32Prefix,
570-
RPCAddress: fmt.Sprintf("http://%s:26657", op.Minitia.GetFullNode().Name()),
577+
RPCAddress: fmt.Sprintf("http://%s:26657", op.Minitia.GetFullNode().HostName()),
571578
GasPrice: "",
572579
GasAdjustment: op.Minitia.Config().GasAdjustment,
573580
TxTimeout: 10,
@@ -576,7 +583,7 @@ func (op OPTestHelper) ExecutorConfig() *executortypes.Config {
576583
DANode: executortypes.NodeConfig{
577584
ChainID: op.DA.Config().ChainID,
578585
Bech32Prefix: op.DA.Config().Bech32Prefix,
579-
RPCAddress: fmt.Sprintf("http://%s:26657", op.DA.GetFullNode().Name()),
586+
RPCAddress: fmt.Sprintf("http://%s:26657", op.DA.GetFullNode().HostName()),
580587
GasPrice: op.DA.Config().GasPrices,
581588
GasAdjustment: op.DA.Config().GasAdjustment,
582589
TxTimeout: 10,

e2e/multiple_txs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestMultipleDepositsAndWithdrawals(t *testing.T) {
5959

6060
ctx := context.Background()
6161

62-
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, daChainConfig, bridgeConfig)
62+
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, daChainConfig, bridgeConfig, ibc.CosmosRly)
6363

6464
user0 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)
6565
user1 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)

e2e/reconnect_node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestReconnectNodes(t *testing.T) {
5454

5555
ctx := context.Background()
5656

57-
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, daChainConfig, bridgeConfig)
57+
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, daChainConfig, bridgeConfig, ibc.CosmosRly)
5858
err := op.Relayer.PauseRelayer(ctx)
5959
require.NoError(t, err)
6060

executor/batchsubmitter/batch_submitter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
1212

13+
coretypes "github.com/cometbft/cometbft/rpc/core/types"
1314
executortypes "github.com/initia-labs/opinit-bots/executor/types"
1415
"github.com/initia-labs/opinit-bots/node"
1516
btypes "github.com/initia-labs/opinit-bots/node/broadcaster/types"
@@ -20,7 +21,9 @@ import (
2021
)
2122

2223
type hostNode interface {
24+
ChainId() string
2325
QueryBatchInfos(context.Context, uint64) (*ophosttypes.QueryBatchInfosResponse, error)
26+
QueryBlock(ctx context.Context, height int64) (*coretypes.ResultBlock, error)
2427
}
2528

2629
type BatchSubmitter struct {

0 commit comments

Comments
 (0)