forked from babylonlabs-io/babylon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.go
65 lines (51 loc) · 2.25 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
epochingtypes "github.com/babylonlabs-io/babylon/x/epoching/types"
"github.com/babylonlabs-io/babylon/x/zoneconcierge/types"
)
type Hooks struct {
k Keeper
}
// ensures Hooks implements ClientHooks interfaces
var _ checkpointingtypes.CheckpointingHooks = Hooks{}
var _ epochingtypes.EpochingHooks = Hooks{}
func (k Keeper) Hooks() Hooks { return Hooks{k} }
func (h Hooks) AfterEpochEnds(ctx context.Context, epoch uint64) {
// upon an epoch has ended, index the current chain info for each CZ
// TODO: do this together when epoch is sealed?
for _, chainID := range h.k.GetAllChainIDs(ctx) {
h.k.recordEpochChainInfo(ctx, chainID, epoch)
}
}
func (h Hooks) AfterRawCheckpointSealed(ctx context.Context, epoch uint64) error {
// upon a raw checkpoint is sealed, index the current chain info for each consumer,
// and generate/save the proof that the epoch is sealed
h.k.recordEpochChainInfoProofs(ctx, epoch)
h.k.recordSealedEpochProof(ctx, epoch)
return nil
}
// AfterRawCheckpointFinalized is triggered upon an epoch has been finalised
func (h Hooks) AfterRawCheckpointFinalized(ctx context.Context, epoch uint64) error {
headersToBroadcast := h.k.getHeadersToBroadcast(ctx)
// send BTC timestamp to all open channels with ZoneConcierge
h.k.BroadcastBTCTimestamps(ctx, epoch, headersToBroadcast)
// Update the last broadcasted segment
h.k.setLastSentSegment(ctx, &types.BTCChainSegment{
BtcHeaders: headersToBroadcast,
})
return nil
}
// Other unused hooks
func (h Hooks) AfterBlsKeyRegistered(ctx context.Context, valAddr sdk.ValAddress) error { return nil }
func (h Hooks) AfterRawCheckpointConfirmed(ctx context.Context, epoch uint64) error { return nil }
func (h Hooks) AfterRawCheckpointForgotten(ctx context.Context, ckpt *checkpointingtypes.RawCheckpoint) error {
return nil
}
func (h Hooks) AfterRawCheckpointBlsSigVerified(ctx context.Context, ckpt *checkpointingtypes.RawCheckpoint) error {
return nil
}
func (h Hooks) AfterEpochBegins(ctx context.Context, epoch uint64) {}
func (h Hooks) BeforeSlashThreshold(ctx context.Context, valSet epochingtypes.ValidatorSet) {}