Skip to content

Commit 351a6d9

Browse files
committed
chore: halt skyway batches during attestations
1 parent 9d4ba40 commit 351a6d9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

x/skyway/abci.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,31 @@ func createBatch(ctx context.Context, k keeper.Keeper) error {
160160
if err != nil {
161161
return err
162162
}
163+
164+
lkup := make(map[string]bool)
163165
for _, erc20ToDenom := range denoms {
166+
pendingAttestation, ok := lkup[erc20ToDenom.ChainReferenceId]
167+
if !ok {
168+
att, err := k.GetAttestations(ctx, &types.QueryAttestationsRequest{
169+
ChainReferenceId: erc20ToDenom.ChainReferenceId,
170+
OrderBy: "desc",
171+
Height: 1,
172+
})
173+
if err != nil {
174+
return fmt.Errorf("failed to get attestations: %w", err)
175+
}
176+
177+
pendingAttestation = len(att.Attestations) > 0 && att.Attestations[0].Observed
178+
lkup[erc20ToDenom.ChainReferenceId] = pendingAttestation
179+
}
180+
181+
if pendingAttestation {
182+
// If the latest attestation is not observed,
183+
// we don't want to create new batches to avoid sending an
184+
// already sent but not yet acknowleged transaction again.
185+
return nil
186+
}
187+
164188
tokenContract, err := k.GetERC20OfDenom(ctx, erc20ToDenom.GetChainReferenceId(), erc20ToDenom.Denom)
165189
if err != nil {
166190
return err

0 commit comments

Comments
 (0)