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

add l1 block height to output type #104

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
134 changes: 97 additions & 37 deletions api/opinit/ophost/v1/types.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions proto/opinit/ophost/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ message TokenPair {
message Output {
// Hash of the l2 output.
bytes output_root = 1;
// The l1 block number that the output root was submitted in.
uint64 l1_block_number = 2;
// Timestamp of the l1 block that the output root was submitted in.
google.protobuf.Timestamp l1_block_time = 2
google.protobuf.Timestamp l1_block_time = 3
[(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// The l2 block number that the output root was submitted in.
uint64 l2_block_number = 3;
uint64 l2_block_number = 4;
}

// BatchInfoWithOutput defines the batch information with output.
Expand Down
6 changes: 6 additions & 0 deletions x/ophost/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ func Test_GenesisExport(t *testing.T) {
output1 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockTime: time.Now().UTC(),
L1BlockNumber: 1,
L2BlockNumber: 100,
}
output2 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockTime: time.Now().UTC(),
L1BlockNumber: 2,
L2BlockNumber: 200,
}
output3 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockTime: time.Now().UTC(),
L1BlockNumber: 1,
L2BlockNumber: 100,
}
require.NoError(t, input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, output1))
Expand Down Expand Up @@ -118,16 +121,19 @@ func Test_GenesisImportExport(t *testing.T) {
}
output1 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 100,
}
output2 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 2,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 200,
}
output3 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 100,
}
Expand Down
1 change: 1 addition & 0 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (ms MsgServer) ProposeOutput(ctx context.Context, req *types.MsgProposeOutp
// store output proposal
if err := ms.SetOutputProposal(ctx, bridgeId, outputIndex, types.Output{
OutputRoot: outputRoot,
L1BlockNumber: uint64(sdkCtx.BlockHeight()),
L1BlockTime: sdkCtx.BlockTime(),
L2BlockNumber: l2BlockNumber,
}); err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func Test_ProposeOutput(t *testing.T) {
require.NoError(t, err)
require.Equal(t, types.Output{
OutputRoot: []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
L1BlockNumber: uint64(ctx.BlockHeight()),
L1BlockTime: blockTime,
L2BlockNumber: 100,
}, output)
Expand Down
8 changes: 8 additions & 0 deletions x/ophost/keeper/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ func Test_IterateOutputProposal(t *testing.T) {
ctx, input := createDefaultTestInput(t)
output1 := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 101,
}
output2 := types.Output{
OutputRoot: []byte{4, 5, 6},
L1BlockNumber: 2,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 102,
}
output3 := types.Output{
OutputRoot: []byte{7, 8, 9},
L1BlockNumber: 3,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 103,
}
output4 := types.Output{
OutputRoot: []byte{10, 11, 12},
L1BlockNumber: 4,
L1BlockTime: time.Now().UTC(),
L2BlockNumber: 104,
}
Expand Down Expand Up @@ -93,6 +97,7 @@ func Test_IsFinalized(t *testing.T) {
proposeTime := time.Now().UTC()
err = input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: proposeTime,
L2BlockNumber: 100,
})
Expand Down Expand Up @@ -151,6 +156,7 @@ func Test_GetLastFinalizedOutput(t *testing.T) {
proposeTime := time.Now().UTC()
err = input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: proposeTime,
L2BlockNumber: 100,
})
Expand All @@ -166,6 +172,7 @@ func Test_GetLastFinalizedOutput(t *testing.T) {
require.Equal(t, uint64(1), index)
require.Equal(t, types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: proposeTime,
L2BlockNumber: 100,
}, output)
Expand All @@ -176,6 +183,7 @@ func Test_DeleteOutputProposal(t *testing.T) {

output := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockNumber: 1,
L1BlockTime: ctx.BlockTime(),
L2BlockNumber: 100,
}
Expand Down
Loading
Loading