Skip to content

Commit 527bf38

Browse files
Feature: add recover IBC client
1 parent 10a3f3d commit 527bf38

14 files changed

+90
-14
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ linters:
1010
- errcheck
1111
- ineffassign
1212
- containedctx
13-
- tenv
13+
- usetesting
1414
- musttag
1515
- mirror
1616
- tagalign

cmd/api/docs/docs.go

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/api/docs/swagger.json

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/api/docs/swagger.yaml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/api/handler/constant_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *ConstantTestSuite) TestEnums() {
6161
var enums responses.Enums
6262
err := json.NewDecoder(rec.Body).Decode(&enums)
6363
s.Require().NoError(err)
64-
s.Require().Len(enums.ActionType, 15)
64+
s.Require().Len(enums.ActionType, 16)
6565
s.Require().Len(enums.Status, 2)
6666
}
6767

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.5
44

55
require (
66
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.36.5-20240911152449-eeebd3decdce.1
7-
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250211170247-cc9150a96f73.1
7+
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250305185440-67be222cd557.1
88
cosmossdk.io/errors v1.0.1
99
github.com/cometbft/cometbft v0.38.17
1010
github.com/cosmos/btcutil v1.0.5

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.35.1-20241016184443-
66
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.35.1-20241016184443-c3b7ab6e57dc.1/go.mod h1:XtXAwi+0M8MZWFDcda/0ShK1PKcFsLmdQOA6VKZdKVg=
77
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250211170247-cc9150a96f73.1 h1:zinklY1DYGxWpbM+IiXrtD/xDZdZwcoZUU3y/tqiea0=
88
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250211170247-cc9150a96f73.1/go.mod h1:kUAF1bkQM31JxAvOGhAEhl/0+p0AlPiAgHRbg6sbfck=
9+
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250305185440-67be222cd557.1 h1:rklx88gB2VhdY1QgOd5ZTNuEEzNhmno/bFFLX1E3UK8=
10+
buf.build/gen/go/astria/protocol-apis/protocolbuffers/go v1.36.5-20250305185440-67be222cd557.1/go.mod h1:kUAF1bkQM31JxAvOGhAEhl/0+p0AlPiAgHRbg6sbfck=
911
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
1012
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
1113
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=

internal/storage/postgres/migrations/200220205_add_bridge_transfer.go internal/storage/postgres/migrations/15032025_add_recover_ibc_client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func init() {
1515
}
1616

1717
func upAddBridgeTransfer(ctx context.Context, db *bun.DB) error {
18-
_, err := db.ExecContext(ctx, `ALTER TYPE action_type ADD VALUE ? AFTER ?`, types.ActionTypeBridgeTransfer.String(), types.ActionTypeIbcSudoChangeAction.String())
18+
_, err := db.ExecContext(ctx, `ALTER TYPE action_type ADD VALUE ? AFTER ?`, types.ActionTypeRecoverIbcClient.String(), types.ActionTypeBridgeTransfer.String())
1919
return err
2020
}
2121
func downAddBridgeTransfer(ctx context.Context, db *bun.DB) error {

internal/storage/types/action_type.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ package types
2323
bridge_sudo_change_action,
2424
fee_change,
2525
ibc_sudo_change_action,
26-
bridge_transfer
26+
bridge_transfer,
27+
recover_ibc_client
2728
)
2829
*/
2930
//go:generate go-enum --marshal --sql --values --names

internal/storage/types/action_type_enum.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/storage/types/action_type_mask.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
ActionTypeFeeChangeBits
2323
ActionTypeIbcSudoChangeBits
2424
ActionTypeBridgeTransferBits
25+
ActionTypeRecoverIbcClientBits
2526
)
2627

2728
var (
@@ -41,6 +42,7 @@ var (
4142
ActionTypeFeeChange: ActionTypeFeeChangeBits,
4243
ActionTypeIbcSudoChangeAction: ActionTypeIbcSudoChangeBits,
4344
ActionTypeBridgeTransfer: ActionTypeBridgeTransferBits,
45+
ActionTypeRecoverIbcClient: ActionTypeRecoverIbcClientBits,
4446
}
4547
)
4648

@@ -82,6 +84,8 @@ func NewActionTypeMask(vals ...string) ActionTypeMask {
8284
mask.Set(ActionTypeIbcSudoChangeBits)
8385
case string(ActionTypeBridgeTransfer):
8486
mask.Set(ActionTypeBridgeTransferBits)
87+
case string(ActionTypeRecoverIbcClient):
88+
mask.Set(ActionTypeRecoverIbcClientBits)
8589
}
8690
}
8791

@@ -98,7 +102,7 @@ func (mask ActionTypeMask) Strings() []string {
98102
}
99103

100104
vals := make([]string, 0)
101-
for val := ActionTypeTransferBits; val <= ActionTypeBridgeTransferBits; val <<= 1 {
105+
for val := ActionTypeTransferBits; val <= ActionTypeRecoverIbcClientBits; val <<= 1 {
102106
if !mask.Has(val) {
103107
continue
104108
}
@@ -133,6 +137,8 @@ func (mask ActionTypeMask) Strings() []string {
133137
vals = append(vals, string(ActionTypeIbcSudoChangeAction))
134138
case ActionTypeBridgeTransferBits:
135139
vals = append(vals, string(ActionTypeBridgeTransfer))
140+
case ActionTypeRecoverIbcClientBits:
141+
vals = append(vals, string(ActionTypeRecoverIbcClient))
136142
}
137143
}
138144

internal/storage/types/action_type_mask_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ func TestActionTypeMask(t *testing.T) {
117117
require.Equal(t, arr, mask.Strings())
118118
})
119119

120+
t.Run("recover ibc client", func(t *testing.T) {
121+
arr := []string{string(ActionTypeRecoverIbcClient)}
122+
123+
mask := NewActionTypeMask(arr...)
124+
require.Equal(t, arr, mask.Strings())
125+
})
126+
120127
t.Run("unknown", func(t *testing.T) {
121128
arr := []string{"unknown"}
122129

pkg/indexer/decode/actions.go

+16
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func parseActions(height types.Level, blockTime time.Time, from string, tx *Deco
101101
case *astria.Action_BridgeTransfer:
102102
tx.ActionTypes.Set(storageTypes.ActionTypeBridgeTransferBits)
103103
err = parseBridgeTransfer(val, height, ctx, &actions[i])
104+
105+
case *astria.Action_RecoverIbcClient:
106+
tx.ActionTypes.Set(storageTypes.ActionTypeRecoverIbcClientBits)
107+
err = parseRecoverIbcClient(val, height, ctx, &actions[i])
108+
104109
default:
105110
return nil, errors.Errorf(
106111
"unknown action type | position = %d | block = %d: %##v",
@@ -932,3 +937,14 @@ func parseBridgeTransfer(body *astria.Action_BridgeTransfer, height types.Level,
932937
}
933938
return nil
934939
}
940+
941+
func parseRecoverIbcClient(body *astria.Action_RecoverIbcClient, height types.Level, ctx *Context, action *storage.Action) error {
942+
action.Type = storageTypes.ActionTypeRecoverIbcClient
943+
action.Data = make(map[string]any)
944+
945+
if body.RecoverIbcClient != nil {
946+
action.Data["client_id"] = body.RecoverIbcClient.GetClientId()
947+
action.Data["replacement_client_id"] = body.RecoverIbcClient.GetReplacementClientId()
948+
}
949+
return nil
950+
}

pkg/indexer/decode/actions_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -1823,4 +1823,31 @@ func TestDecodeActions(t *testing.T) {
18231823
require.NoError(t, err)
18241824
require.Equal(t, wantAction, action)
18251825
})
1826+
1827+
t.Run("recover ibc client", func(t *testing.T) {
1828+
decodeContext := NewContext(map[string]string{})
1829+
1830+
message := &astria.Action_RecoverIbcClient{
1831+
RecoverIbcClient: &astria.RecoverIbcClient{
1832+
ClientId: "old_client_id",
1833+
ReplacementClientId: "new_client_id",
1834+
},
1835+
}
1836+
1837+
wantAction := storage.Action{
1838+
Type: types.ActionTypeRecoverIbcClient,
1839+
Data: map[string]any{
1840+
"client_id": "old_client_id",
1841+
"replacement_client_id": "new_client_id",
1842+
},
1843+
Height: 1000,
1844+
}
1845+
1846+
action := storage.Action{
1847+
Height: 1000,
1848+
}
1849+
err := parseRecoverIbcClient(message, 1000, &decodeContext, &action)
1850+
require.NoError(t, err)
1851+
require.Equal(t, wantAction, action)
1852+
})
18261853
}

0 commit comments

Comments
 (0)