-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finality: evidence storage and handler (#18)
- Loading branch information
1 parent
17855d8
commit c46b30f
Showing
12 changed files
with
1,065 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
package babylon.finality.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "babylon/finality/v1/finality.proto"; | ||
|
||
option go_package = "github.com/babylonchain/babylon/x/finality/types"; | ||
|
||
// EventSlashedBTCValidator is the event emitted when a BTC validator is slashed | ||
// due to signing two conflicting blocks | ||
message EventSlashedBTCValidator { | ||
// val_btc_pk is the BTC validator's BTC PK | ||
bytes val_btc_pk = 1 [ (gogoproto.customtype) = "github.com/babylonchain/babylon/types.BIP340PubKey" ]; | ||
// indexed_block is the canonical block at this height | ||
IndexedBlock indexed_block = 2; | ||
// evidence is the evidence that the BTC validator double signs | ||
Evidence evidence = 3; | ||
// extracted_btc_sk is the extracted BTC SK of this BTC validator | ||
bytes extracted_btc_sk = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package keeper | ||
|
||
import ( | ||
bbn "github.com/babylonchain/babylon/types" | ||
"github.com/babylonchain/babylon/x/finality/types" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) SetEvidence(ctx sdk.Context, evidence *types.Evidence) { | ||
store := k.evidenceStore(ctx, evidence.BlockHeight) | ||
store.Set(evidence.ValBtcPk.MustMarshal(), k.cdc.MustMarshal(evidence)) | ||
} | ||
|
||
func (k Keeper) HasEvidence(ctx sdk.Context, height uint64, valBtcPK *bbn.BIP340PubKey) bool { | ||
store := k.evidenceStore(ctx, height) | ||
return store.Has(valBtcPK.MustMarshal()) | ||
} | ||
|
||
func (k Keeper) GetEvidence(ctx sdk.Context, height uint64, valBtcPK *bbn.BIP340PubKey) (*types.Evidence, error) { | ||
if uint64(ctx.BlockHeight()) < height { | ||
return nil, types.ErrHeightTooHigh | ||
} | ||
store := k.evidenceStore(ctx, height) | ||
evidenceBytes := store.Get(valBtcPK.MustMarshal()) | ||
if len(evidenceBytes) == 0 { | ||
return nil, types.ErrEvidenceNotFound | ||
} | ||
var evidence types.Evidence | ||
k.cdc.MustUnmarshal(evidenceBytes, &evidence) | ||
return &evidence, nil | ||
} | ||
|
||
// evidenceStore returns the KVStore of the evidences | ||
// prefix: EvidenceKey | ||
// key: (block height || BTC validator PK) | ||
// value: Evidence | ||
func (k Keeper) evidenceStore(ctx sdk.Context, height uint64) prefix.Store { | ||
store := ctx.KVStore(k.storeKey) | ||
prefixedStore := prefix.NewStore(store, types.EvidenceKey) | ||
return prefix.NewStore(prefixedStore, sdk.Uint64ToBigEndian(height)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package types | ||
|
||
import ( | ||
bbn "github.com/babylonchain/babylon/types" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
) | ||
|
||
func NewEventSlashedBTCValidator(valBTCPK *bbn.BIP340PubKey, indexedBlock *IndexedBlock, evidence *Evidence, btcSK *btcec.PrivateKey) *EventSlashedBTCValidator { | ||
return &EventSlashedBTCValidator{ | ||
ValBtcPk: valBTCPK, | ||
IndexedBlock: indexedBlock, | ||
Evidence: evidence, | ||
ExtractedBtcSk: btcSK.Serialize(), | ||
} | ||
} |
Oops, something went wrong.