diff --git a/proto/babylon/checkpointing/checkpoint.proto b/proto/babylon/checkpointing/checkpoint.proto index 2c5888dde..56ee25722 100644 --- a/proto/babylon/checkpointing/checkpoint.proto +++ b/proto/babylon/checkpointing/checkpoint.proto @@ -28,18 +28,24 @@ message RawCheckpointWithMeta { RawCheckpoint ckpt = 1; // status defines the status of the checkpoint CheckpointStatus status = 2; + // power_sum defines the accumulated voting power for the checkpoint + uint64 power_sum = 3; } // CkptStatus is the status of a checkpoint. enum CheckpointStatus { option (gogoproto.goproto_enum_prefix) = false; - // UNCHECKPOINTED defines a checkpoint that is checkpointed on BTC. - CKPT_STATUS_UNCHECKPOINTED = 0 [(gogoproto.enumvalue_customname) = "Uncheckpointed"]; - // UNCONFIRMED defines a validator that is checkpointed on BTC but not confirmed. - CKPT_STATUS_UNCONFIRMED = 1 [(gogoproto.enumvalue_customname) = "Unconfirmed"]; - // CONFIRMED defines a validator that is confirmed on BTC. - CKPT_STATUS_CONFIRMED = 2 [(gogoproto.enumvalue_customname) = "Confirmed"]; + // ACCUMULATING defines a checkpoint that is awaiting for BLS signatures. + CKPT_STATUS_ACCUMULATING = 0 [(gogoproto.enumvalue_customname) = "Accumulating"]; + // SIGNED defines a checkpoint that has accumulated sufficient BLS signatures. + CKPT_STATUS_SIGNED = 1 [(gogoproto.enumvalue_customname) = "Unconfirmed"]; + // SUBMITTED defines a checkpoint that is included on BTC. + CKPT_STATUS_SUBMITTED = 2 [(gogoproto.enumvalue_customname) = "Submitted"]; + // CONFIRMED defines a checkpoint that is k-deep on BTC. + CKPT_STATUS_CONFIRMED = 3 [(gogoproto.enumvalue_customname) = "Confirmed"]; + // FINALIZED defines a checkpoint that is w-deep on BTC. + CKPT_STATUS_FINALIZED = 4 [(gogoproto.enumvalue_customname) = "Finalized"]; } // BlsSig wraps the bls sig with meta data. diff --git a/x/checkpointing/abci.go b/x/checkpointing/abci.go new file mode 100644 index 000000000..30c876088 --- /dev/null +++ b/x/checkpointing/abci.go @@ -0,0 +1,47 @@ +package checkpointing + +import ( + "github.com/babylonchain/babylon/x/checkpointing/types" + "time" + + "github.com/babylonchain/babylon/x/checkpointing/keeper" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +// BeginBlocker is called at the beginning of every block. +// Upon each BeginBlock, if reaching the second block after the epoch begins, then +// - extract the LastCommitHash from the block +// - create a raw checkpoint with the status of ACCUMULATING +// - start a BLS signer which creates a BLS sig transaction and distributes it to the network + +func BeginBlocker(ctx sdk.Context, k keeper.Keeper, req abci.RequestBeginBlock) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + + // get the height of the last block in this epoch + epochBoundary := k.GetEpochBoundary(ctx) + // if this block is the second block of an epoch + // TODO: it's not correct, we want the epoch boundary of the previous epoch + if uint64(ctx.BlockHeight())-2 == epochBoundary.Uint64() { + // note that this epochNum is obtained before the BeginBlocker of the epoching module is executed + // meaning that the epochNum has not been incremented upon a new epoch + epochNum := k.GetEpochNumber(ctx) + lch := ctx.BlockHeader().LastCommitHash + err := k.BuildRawCheckpoint(ctx, epochNum, lch) + if err != nil { + panic("failed to generate a raw checkpoint") + } + + // emit BeginEpoch event + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeRawCheckpointGenerated, + sdk.NewAttribute(types.AttributeKeyEpochNumber, k.GetEpochNumber(ctx).String()), + ), + }) + + // TODO: call BLS signer to send a BLS-sig transaction + } +} diff --git a/x/checkpointing/keeper/ckpt_state.go b/x/checkpointing/keeper/ckpt_state.go index 4aab61fb7..9a99c1392 100644 --- a/x/checkpointing/keeper/ckpt_state.go +++ b/x/checkpointing/keeper/ckpt_state.go @@ -17,21 +17,20 @@ func (k Keeper) CheckpointsState(ctx sdk.Context) CheckpointsState { store := ctx.KVStore(k.storeKey) return CheckpointsState{ cdc: k.cdc, - checkpoints: prefix.NewStore(store, types.CheckpointsPrefix), + checkpoints: prefix.NewStore(store, types.CkptsObjectPrefix), } } // CreateRawCkptWithMeta inserts the raw checkpoint with meta into the storage by its epoch number // a new checkpoint is created with the status of UNCEHCKPOINTED -func (cs CheckpointsState) CreateRawCkptWithMeta(ckpt *types.RawCheckpoint) error { - // save concrete ckpt object - ckptWithMeta := types.NewCheckpointWithMeta(ckpt, types.Uncheckpointed) - - if cs.checkpoints.Has(types.CkptsObjectKey(ckpt.EpochNum)) { - return types.ErrCkptAlreadyExist.Wrapf("a raw checkpoint already exists at epoch %v", ckpt.EpochNum) +func (cs CheckpointsState) CreateRawCkptWithMeta(ckptWithMeta *types.RawCheckpointWithMeta) error { + epoch := ckptWithMeta.Ckpt.EpochNum + if cs.checkpoints.Has(types.CkptsObjectKey(epoch)) { + return types.ErrCkptAlreadyExist.Wrapf("a raw checkpoint already exists at epoch %v", epoch) } - cs.checkpoints.Set(types.CkptsObjectKey(ckpt.EpochNum), types.CkptWithMetaToBytes(cs.cdc, ckptWithMeta)) + // save concrete ckpt object + cs.checkpoints.Set(types.CkptsObjectKey(epoch), types.CkptWithMetaToBytes(cs.cdc, ckptWithMeta)) return nil } diff --git a/x/checkpointing/keeper/keeper.go b/x/checkpointing/keeper/keeper.go index 02d3ba250..b138f3551 100644 --- a/x/checkpointing/keeper/keeper.go +++ b/x/checkpointing/keeper/keeper.go @@ -68,10 +68,14 @@ func (k Keeper) AddBlsSig(ctx sdk.Context, sig *types.BlsSig) error { } // AddRawCheckpoint adds a raw checkpoint into the storage -// this API may not needed since checkpoints are generated internally -func (k Keeper) AddRawCheckpoint(ctx sdk.Context, ckpt *types.RawCheckpoint) error { - // NOTE: may remove this API - return k.CheckpointsState(ctx).CreateRawCkptWithMeta(ckpt) +func (k Keeper) AddRawCheckpoint(ctx sdk.Context, ckptWithMeta *types.RawCheckpointWithMeta) error { + return k.CheckpointsState(ctx).CreateRawCkptWithMeta(ckptWithMeta) +} + +func (k Keeper) BuildRawCheckpoint(ctx sdk.Context, epochNum sdk.Uint, lch types.LastCommitHash) error { + ckptWithMeta := types.NewCheckpointWithMeta(types.NewCheckpoint(epochNum, lch), types.Accumulating) + + return k.AddRawCheckpoint(ctx, ckptWithMeta) } // CheckpointEpoch verifies checkpoint from BTC and returns epoch number @@ -105,3 +109,11 @@ func (k Keeper) UpdateCkptStatus(ctx sdk.Context, rawCkptBytes []byte, status ty func (k Keeper) CreateRegistration(ctx sdk.Context, blsPubKey bls12381.PublicKey, valAddr types.ValidatorAddress) error { return k.RegistrationState(ctx).CreateRegistration(blsPubKey, valAddr) } + +func (k Keeper) GetEpochBoundary(ctx sdk.Context) sdk.Uint { + return k.epochingKeeper.GetEpochBoundary(ctx) +} + +func (k Keeper) GetEpochNumber(ctx sdk.Context) sdk.Uint { + return k.epochingKeeper.GetEpochNumber(ctx) +} diff --git a/x/checkpointing/module.go b/x/checkpointing/module.go index 13c16bd78..eaa4e9dd0 100644 --- a/x/checkpointing/module.go +++ b/x/checkpointing/module.go @@ -168,7 +168,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + BeginBlocker(ctx, am.keeper, req) +} // EndBlock executes all ABCI EndBlock logic respective to the capability module. It // returns no validator updates. diff --git a/x/checkpointing/types/blssig_set.go b/x/checkpointing/types/blssig_set.go deleted file mode 100644 index 5a0a982e7..000000000 --- a/x/checkpointing/types/blssig_set.go +++ /dev/null @@ -1,39 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/libs/bits" - "github.com/tendermint/tendermint/libs/bytes" -) - -type BlsSigSet struct { - epoch uint16 - lastCommitHash bytes.HexBytes - validators types.Validators - - sum uint64 - sigsBitArray *bits.BitArray -} - -// NewBlsSigSet constructs a new BlsSigSet struct used to accumulate bls sigs for a given epoch -func NewBlsSigSet(epoch uint16, lastCommitHash bytes.HexBytes, validators types.Validators) *BlsSigSet { - return &BlsSigSet{ - epoch: epoch, - lastCommitHash: lastCommitHash, - validators: validators, - sum: 0, - sigsBitArray: bits.NewBitArray(validators.Len()), - } -} - -func (bs *BlsSigSet) AddBlsSig(sig *BlsSig) (bool, error) { - return bs.addBlsSig(sig) -} - -func (bs *BlsSigSet) addBlsSig(sig *BlsSig) (bool, error) { - panic("implement this!") -} - -func (bs *BlsSigSet) MakeRawCheckpoint() *RawCheckpoint { - panic("implement this!") -} diff --git a/x/checkpointing/types/checkpoint.pb.go b/x/checkpointing/types/checkpoint.pb.go index c9ecb8047..8d95bf2da 100644 --- a/x/checkpointing/types/checkpoint.pb.go +++ b/x/checkpointing/types/checkpoint.pb.go @@ -31,24 +31,32 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type CheckpointStatus int32 const ( - // UNCHECKPOINTED defines a checkpoint that is checkpointed on BTC. - Uncheckpointed CheckpointStatus = 0 - // UNCONFIRMED defines a validator that is checkpointed on BTC but not confirmed. + // ACCUMULATING defines a checkpoint that is awaiting for BLS signatures. + Accumulating CheckpointStatus = 0 + // SIGNED defines a checkpoint that has accumulated sufficient BLS signatures. Unconfirmed CheckpointStatus = 1 - // CONFIRMED defines a validator that is confirmed on BTC. - Confirmed CheckpointStatus = 2 + // SUBMITTED defines a checkpoint that is included on BTC. + Submitted CheckpointStatus = 2 + // CONFIRMED defines a checkpoint that is k-deep on BTC. + Confirmed CheckpointStatus = 3 + // FINALIZED defines a checkpoint that is w-deep on BTC. + Finalized CheckpointStatus = 4 ) var CheckpointStatus_name = map[int32]string{ - 0: "CKPT_STATUS_UNCHECKPOINTED", - 1: "CKPT_STATUS_UNCONFIRMED", - 2: "CKPT_STATUS_CONFIRMED", + 0: "CKPT_STATUS_ACCUMULATING", + 1: "CKPT_STATUS_SIGNED", + 2: "CKPT_STATUS_SUBMITTED", + 3: "CKPT_STATUS_CONFIRMED", + 4: "CKPT_STATUS_FINALIZED", } var CheckpointStatus_value = map[string]int32{ - "CKPT_STATUS_UNCHECKPOINTED": 0, - "CKPT_STATUS_UNCONFIRMED": 1, - "CKPT_STATUS_CONFIRMED": 2, + "CKPT_STATUS_ACCUMULATING": 0, + "CKPT_STATUS_SIGNED": 1, + "CKPT_STATUS_SUBMITTED": 2, + "CKPT_STATUS_CONFIRMED": 3, + "CKPT_STATUS_FINALIZED": 4, } func (x CheckpointStatus) String() string { @@ -130,6 +138,8 @@ type RawCheckpointWithMeta struct { Ckpt *RawCheckpoint `protobuf:"bytes,1,opt,name=ckpt,proto3" json:"ckpt,omitempty"` // status defines the status of the checkpoint Status CheckpointStatus `protobuf:"varint,2,opt,name=status,proto3,enum=babylon.checkpointing.v1.CheckpointStatus" json:"status,omitempty"` + // power_sum defines the accumulated voting power for the checkpoint + PowerSum uint64 `protobuf:"varint,3,opt,name=power_sum,json=powerSum,proto3" json:"power_sum,omitempty"` } func (m *RawCheckpointWithMeta) Reset() { *m = RawCheckpointWithMeta{} } @@ -176,7 +186,14 @@ func (m *RawCheckpointWithMeta) GetStatus() CheckpointStatus { if m != nil { return m.Status } - return Uncheckpointed + return Accumulating +} + +func (m *RawCheckpointWithMeta) GetPowerSum() uint64 { + if m != nil { + return m.PowerSum + } + return 0 } // BlsSig wraps the bls sig with meta data. @@ -259,42 +276,46 @@ func init() { } var fileDescriptor_63ff05f0a47b36f7 = []byte{ - // 558 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0x5f, 0x6b, 0xd3, 0x50, - 0x18, 0xc6, 0x73, 0xb6, 0x5a, 0xdd, 0x99, 0xad, 0x25, 0x38, 0x8d, 0x11, 0xd2, 0x50, 0x50, 0xcb, - 0x90, 0x84, 0x76, 0x08, 0xfe, 0xc1, 0x8b, 0x35, 0xab, 0x6c, 0x8c, 0xb6, 0x23, 0x69, 0x15, 0xbc, - 0x09, 0x27, 0x69, 0x96, 0x1c, 0x96, 0xe4, 0x84, 0x9c, 0x13, 0xb5, 0xdf, 0x40, 0x7a, 0xe5, 0xa5, - 0x37, 0x05, 0x41, 0x3f, 0x8c, 0x97, 0xbb, 0x10, 0x14, 0x2f, 0x44, 0xda, 0x1b, 0x3f, 0x86, 0x24, - 0xa9, 0xeb, 0x5a, 0x18, 0xde, 0xec, 0x2e, 0xef, 0x73, 0x9e, 0x5f, 0x92, 0xf7, 0x07, 0x07, 0xde, - 0xb7, 0x90, 0x35, 0xf2, 0x49, 0xa8, 0xda, 0x9e, 0x63, 0x9f, 0x44, 0x04, 0x87, 0x0c, 0x87, 0xee, - 0xb9, 0x49, 0x89, 0x62, 0xc2, 0x08, 0x2f, 0xcc, 0x7b, 0xca, 0x52, 0x4f, 0x79, 0xd3, 0x10, 0xef, - 0xd8, 0x84, 0x06, 0x84, 0x9a, 0x59, 0x4f, 0xcd, 0x87, 0x1c, 0x12, 0x6f, 0xba, 0xc4, 0x25, 0x79, - 0x9e, 0x3e, 0xcd, 0xd3, 0xaa, 0x4b, 0x88, 0xeb, 0x3b, 0x6a, 0x36, 0x59, 0xc9, 0xb1, 0xca, 0x70, - 0xe0, 0x50, 0x86, 0x82, 0x28, 0x2f, 0xd4, 0xbe, 0x03, 0x58, 0xd2, 0xd1, 0x5b, 0xed, 0xec, 0x4b, - 0xfc, 0x5d, 0xb8, 0xe1, 0x44, 0xc4, 0xf6, 0xcc, 0x30, 0x09, 0x04, 0x20, 0x83, 0x7a, 0x41, 0xbf, - 0x96, 0x05, 0xdd, 0x24, 0xe0, 0xeb, 0xb0, 0xe2, 0x23, 0xca, 0x4c, 0x9b, 0x04, 0x01, 0x66, 0xa6, - 0x87, 0xa8, 0x27, 0xac, 0xc9, 0xa0, 0x7e, 0x5d, 0x2f, 0xa7, 0xb9, 0x96, 0xc5, 0xfb, 0x88, 0x7a, - 0xf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, 0x1e, 0x66, 0xc6, 0xb9, 0xed, 0x2f, 0x00, 0x56, 0x56, - 0x77, 0xe6, 0x9b, 0x50, 0xd4, 0x0e, 0x8f, 0xfa, 0xa6, 0xd1, 0xdf, 0xed, 0x0f, 0x0c, 0x73, 0xd0, - 0xd5, 0xf6, 0xdb, 0xda, 0xe1, 0x51, 0xef, 0xa0, 0xdb, 0x6f, 0xef, 0x55, 0x38, 0x91, 0x1f, 0x4f, - 0xe4, 0xf2, 0x20, 0x5c, 0xc8, 0x73, 0x86, 0xfc, 0x43, 0x78, 0x7b, 0x85, 0xe9, 0x75, 0x5f, 0x1c, - 0xe8, 0x9d, 0xf6, 0x5e, 0x05, 0x88, 0x37, 0xc6, 0x13, 0x79, 0x73, 0x10, 0xda, 0x24, 0x3c, 0xc6, - 0x71, 0xe0, 0x0c, 0xf9, 0x3a, 0xdc, 0x3a, 0xdf, 0x5e, 0x74, 0xd7, 0xc4, 0xd2, 0x78, 0x22, 0x6f, - 0x68, 0xff, 0x9a, 0x62, 0xe1, 0xfd, 0x67, 0x89, 0x6b, 0xf5, 0xbe, 0x4e, 0x25, 0x70, 0x3a, 0x95, - 0xc0, 0xef, 0xa9, 0x04, 0x3e, 0xcc, 0x24, 0xee, 0x74, 0x26, 0x71, 0x3f, 0x66, 0x12, 0xf7, 0xfa, - 0xd1, 0xff, 0x84, 0xbd, 0x5b, 0xb9, 0xba, 0x6c, 0x14, 0x39, 0xd4, 0x2a, 0x66, 0x57, 0x69, 0xe7, - 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xf9, 0xdf, 0x5c, 0xe0, 0x03, 0x00, 0x00, + // 623 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x6b, 0xd4, 0x4e, + 0x1c, 0xc6, 0x77, 0xda, 0xfc, 0xf6, 0xd7, 0x4e, 0xbb, 0x35, 0x04, 0x2b, 0x71, 0x85, 0x74, 0x29, + 0x68, 0x97, 0x1e, 0x12, 0xda, 0x22, 0xf8, 0x07, 0x0f, 0xbb, 0xd9, 0x6d, 0x5d, 0xec, 0x6e, 0x25, + 0xc9, 0x2a, 0xf4, 0x12, 0x26, 0xd9, 0x34, 0x19, 0x9a, 0xc9, 0x84, 0xcc, 0xc4, 0x5a, 0x5f, 0x81, + 0xf4, 0xe4, 0x1b, 0x28, 0x08, 0xbe, 0x06, 0xdf, 0x83, 0xc7, 0x1e, 0x04, 0xc5, 0x83, 0x48, 0x7b, + 0xf1, 0xe6, 0x5b, 0x90, 0x4c, 0x96, 0xda, 0xad, 0x14, 0x2f, 0xbd, 0xe5, 0x79, 0xe6, 0x79, 0x26, + 0xf9, 0x7e, 0x86, 0x0c, 0xbc, 0xe7, 0x21, 0xef, 0x30, 0xa6, 0x89, 0xe1, 0x47, 0x81, 0xbf, 0x9f, + 0x52, 0x9c, 0x70, 0x9c, 0x84, 0x17, 0x94, 0x9e, 0x66, 0x94, 0x53, 0x45, 0x1d, 0xe7, 0xf4, 0x89, + 0x9c, 0xfe, 0x6a, 0xad, 0x7e, 0xdb, 0xa7, 0x8c, 0x50, 0xe6, 0x8a, 0x9c, 0x51, 0x8a, 0xb2, 0x54, + 0xbf, 0x19, 0xd2, 0x90, 0x96, 0x7e, 0xf1, 0x34, 0x76, 0x97, 0x42, 0x4a, 0xc3, 0x38, 0x30, 0x84, + 0xf2, 0xf2, 0x3d, 0x83, 0x63, 0x12, 0x30, 0x8e, 0x48, 0x5a, 0x06, 0x96, 0xbf, 0x00, 0x58, 0xb3, + 0xd0, 0x81, 0x79, 0xfe, 0x26, 0xe5, 0x0e, 0x9c, 0x0d, 0x52, 0xea, 0x47, 0x6e, 0x92, 0x13, 0x15, + 0x34, 0x40, 0x53, 0xb2, 0x66, 0x84, 0x31, 0xc8, 0x89, 0xd2, 0x84, 0x72, 0x8c, 0x18, 0x77, 0x7d, + 0x4a, 0x08, 0xe6, 0x6e,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0xaa, + 0x81, 0x1f, 0xa7, 0x1a, 0x78, 0x77, 0xa6, 0x55, 0x4e, 0xce, 0xb4, 0xca, 0xd7, 0x33, 0xad, 0xb2, + 0x7b, 0xff, 0x5f, 0xec, 0x5f, 0x5f, 0xba, 0x22, 0xf8, 0x61, 0x1a, 0x30, 0xaf, 0x2a, 0x7e, 0xd9, + 0x8d, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x1c, 0x24, 0xdf, 0x48, 0x04, 0x00, 0x00, } func (this *RawCheckpoint) Equal(that interface{}) bool { @@ -408,6 +429,11 @@ func (m *RawCheckpointWithMeta) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.PowerSum != 0 { + i = encodeVarintCheckpoint(dAtA, i, uint64(m.PowerSum)) + i-- + dAtA[i] = 0x18 + } if m.Status != 0 { i = encodeVarintCheckpoint(dAtA, i, uint64(m.Status)) i-- @@ -530,6 +556,9 @@ func (m *RawCheckpointWithMeta) Size() (n int) { if m.Status != 0 { n += 1 + sovCheckpoint(uint64(m.Status)) } + if m.PowerSum != 0 { + n += 1 + sovCheckpoint(uint64(m.PowerSum)) + } return n } @@ -819,6 +848,25 @@ func (m *RawCheckpointWithMeta) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PowerSum", wireType) + } + m.PowerSum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCheckpoint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PowerSum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCheckpoint(dAtA[iNdEx:]) diff --git a/x/checkpointing/types/expected_keepers.go b/x/checkpointing/types/expected_keepers.go index ee31a0f2e..c64450ff3 100644 --- a/x/checkpointing/types/expected_keepers.go +++ b/x/checkpointing/types/expected_keepers.go @@ -27,6 +27,7 @@ type StakingKeeper interface { type EpochingKeeper interface { GetEpochNumber(ctx sdk.Context) sdk.Uint EnqueueMsg(ctx sdk.Context, msg epochingtypes.QueuedMessage) + GetEpochBoundary(ctx sdk.Context) sdk.Uint } // Event Hooks diff --git a/x/checkpointing/types/keys.go b/x/checkpointing/types/keys.go index 835f92aaa..5d3b7ccb8 100644 --- a/x/checkpointing/types/keys.go +++ b/x/checkpointing/types/keys.go @@ -39,28 +39,27 @@ var ( // BlsSigsObjectKey defines epoch + hash func BlsSigsObjectKey(epoch uint64, hash BlsSigHash) []byte { ee := sdk.Uint64ToBigEndian(epoch) - epochPrefix := append(BlsSigsObjectPrefix, ee...) - return append(epochPrefix, hash...) + return append(ee, hash...) } // BlsSigsEpochKey defines BLS sig hash func BlsSigsEpochKey(hash BlsSigHash) []byte { - return append(BlsSigsHashToEpochPrefix, hash...) + return hash } // CkptsObjectKey defines epoch func CkptsObjectKey(epoch uint64) []byte { - return append(CkptsObjectPrefix, sdk.Uint64ToBigEndian(epoch)...) + return sdk.Uint64ToBigEndian(epoch) } // AddrToBlsKeyKey defines validator address func AddrToBlsKeyKey(valAddr ValidatorAddress) []byte { - return append(AddrToBlsKeyPrefix, []byte(valAddr)...) + return []byte(valAddr) } // BlsKeyToAddrKey defines BLS public key func BlsKeyToAddrKey(pk bls12381.PublicKey) []byte { - return append(BlsKeyToAddrPrefix, pk...) + return pk } func KeyPrefix(p string) []byte { diff --git a/x/checkpointing/types/query.pb.go b/x/checkpointing/types/query.pb.go index 449f522f9..748ab84cf 100644 --- a/x/checkpointing/types/query.pb.go +++ b/x/checkpointing/types/query.pb.go @@ -76,7 +76,7 @@ func (m *QueryRawCheckpointListRequest) GetStatus() CheckpointStatus { if m != nil { return m.Status } - return Uncheckpointed + return Accumulating } func (m *QueryRawCheckpointListRequest) GetPagination() *query.PageRequest { diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 758a8d16b..9eda94ea1 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -3,8 +3,11 @@ package types import ( "bytes" "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) +type LastCommitHash []byte + type ValidatorAddress string type BlsSigHash []byte @@ -19,6 +22,15 @@ func ValAddrToBytes(address ValidatorAddress) []byte { return []byte(address) } +func NewCheckpoint(epochNum sdk.Uint, lch LastCommitHash) *RawCheckpoint { + return &RawCheckpoint{ + EpochNum: epochNum.Uint64(), + LastCommitHash: lch, + Bitmap: nil, + BlsMultiSig: nil, + } +} + func NewCheckpointWithMeta(ckpt *RawCheckpoint, status CheckpointStatus) *RawCheckpointWithMeta { return &RawCheckpointWithMeta{ Ckpt: ckpt,