-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
message validation: check voluntary exit existence (#1468)
message validation: check voluntary exit existence
- Loading branch information
1 parent
86fd07f
commit c5dfdac
Showing
9 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dutystore | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
) | ||
|
||
type VoluntaryExitDuties struct { | ||
mu sync.RWMutex | ||
m map[phase0.Slot]map[phase0.BLSPubKey]int | ||
} | ||
|
||
func NewVoluntaryExit() *VoluntaryExitDuties { | ||
return &VoluntaryExitDuties{ | ||
m: make(map[phase0.Slot]map[phase0.BLSPubKey]int), | ||
} | ||
} | ||
|
||
func (d *VoluntaryExitDuties) GetDutyCount(slot phase0.Slot, pk phase0.BLSPubKey) int { | ||
d.mu.RLock() | ||
defer d.mu.RUnlock() | ||
|
||
v, ok := d.m[slot] | ||
if !ok { | ||
return 0 | ||
} | ||
|
||
return v[pk] | ||
} | ||
|
||
func (d *VoluntaryExitDuties) AddDuty(slot phase0.Slot, pk phase0.BLSPubKey) { | ||
d.mu.Lock() | ||
defer d.mu.Unlock() | ||
|
||
v, ok := d.m[slot] | ||
if !ok { | ||
d.m[slot] = map[phase0.BLSPubKey]int{ | ||
pk: 1, | ||
} | ||
} else { | ||
v[pk]++ | ||
} | ||
} | ||
|
||
func (d *VoluntaryExitDuties) RemoveSlot(slot phase0.Slot) { | ||
d.mu.Lock() | ||
defer d.mu.Unlock() | ||
|
||
delete(d.m, slot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters