Search Apps Documentation Source Content File Folder Download Copy Actions Download

lock.gno

0.93 Kb · 28 lines
 1package v1
 2
 3// assertPoolUnlocked is the read-only reentrancy guard. It reports the global
 4// pool lock state without mutating it, so it is safe to call before the access
 5// checks: a call that aborts on authorization afterwards leaves no persisted
 6// lock behind (which would otherwise leak under interrealm v2, where a panic
 7// crossing the realm boundary skips the deferred unlockPool). It also keeps the
 8// "cannot modify pool while locked" message as the first failure for any
 9// entrypoint invoked while a swap holds the lock (reentrancy protection).
10func (i *poolV1) assertPoolUnlocked() {
11	if i.store.HasUnlocked() && !i.store.GetUnlocked() {
12		panic(errLockedPool)
13	}
14}
15
16func (i *poolV1) lockPool(_ int, rlm realm) {
17	i.assertPoolUnlocked()
18
19	if err := i.store.SetUnlocked(0, rlm, false); err != nil {
20		panic(err)
21	}
22}
23
24func (i *poolV1) unlockPool(_ int, rlm realm) {
25	if err := i.store.SetUnlocked(0, rlm, true); err != nil {
26		panic(err)
27	}
28}