mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 16:25:21 +00:00
20 lines
620 B
Markdown
20 lines
620 B
Markdown
|
# Begin Block
|
||
|
|
||
|
At the start of each block, atomic swaps that have reached `ExpireHeight` are expired. The logic to expire atomic swaps is as follows:
|
||
|
|
||
|
```go
|
||
|
var expiredSwaps [][]byte
|
||
|
k.IterateAtomicSwapsByBlock(ctx, uint64(ctx.BlockHeight()), func(id []byte) bool {
|
||
|
expiredSwaps = append(expiredSwaps, id)
|
||
|
return false
|
||
|
})
|
||
|
|
||
|
// Expire incomplete swaps (claimed swaps have already been removed from byBlock index)
|
||
|
for _, id := range expiredSwaps {
|
||
|
atomicSwap, _ := k.GetAtomicSwap(ctx, id)
|
||
|
atomicSwap.Status = types.Expired
|
||
|
k.SetAtomicSwap(ctx, atomicSwap)
|
||
|
k.RemoveFromByBlockIndex(ctx, atomicSwap)
|
||
|
}
|
||
|
```
|