-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote_extension.go
38 lines (31 loc) · 1.04 KB
/
vote_extension.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
package da
import (
"context"
"encoding/binary"
"fmt"
"time"
"github.com/Wondertan/cocage/modules/da"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func ExtendVoteHandler(da da.Keeper, client Client) sdk.ExtendVoteHandler {
return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
timeoutCtx, cancel := context.WithTimeout(ctx.Context(), time.Second) // ensure we don't block for too long
defer cancel()
resp := &abci.ResponseExtendVote{}
latestHeight, err := da.LatestDataCommitmentHeight(ctx)
if err != nil {
return resp, fmt.Errorf("getting latest commitment DA height: %w", err)
}
latestSampledHeight, err := client.LatestSampledHeight(timeoutCtx)
if err != nil {
return resp, fmt.Errorf("getting DA sampling stats: %w", err)
}
if latestHeight >= latestSampledHeight {
// no new heights sampled, skip...
return resp, nil
}
resp.VoteExtension = binary.LittleEndian.AppendUint64(nil, latestSampledHeight)
return resp, err
}
}