Skip to content

Commit 05531dc

Browse files
committed
Change network to interface in SimpleSigner
1 parent eca3b4b commit 05531dc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

signer/far_future_protection.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ import (
44
"time"
55

66
"github.com/attestantio/go-eth2-client/spec/phase0"
7-
8-
"github.com/bloxapp/eth2-key-manager/core"
97
)
108

119
// FarFutureMaxValidEpoch is the max epoch of far future signing
1210
var FarFutureMaxValidEpoch = int64(time.Minute.Seconds() * 20)
1311

1412
// IsValidFarFutureEpoch prevents far into the future signing request, verify a slot is within the current epoch
1513
// https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/validator.md#protection-best-practices
16-
func IsValidFarFutureEpoch(network core.Network, epoch phase0.Epoch) bool {
14+
func IsValidFarFutureEpoch(network network, epoch phase0.Epoch) bool {
1715
maxValidEpoch := network.EstimatedEpochAtSlot(network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch))
1816
return epoch <= maxValidEpoch
1917
}
2018

2119
// IsValidFarFutureSlot returns true if the given slot is valid
22-
func IsValidFarFutureSlot(network core.Network, slot phase0.Slot) bool {
20+
func IsValidFarFutureSlot(network network, slot phase0.Slot) bool {
2321
maxValidSlot := network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch)
2422
return slot <= maxValidSlot
2523
}

signer/validator_signer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ type ValidatorSigner interface {
3030
SignBLSToExecutionChange(blsToExecutionChange *capella.BLSToExecutionChange, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error)
3131
}
3232

33+
type network interface {
34+
EstimatedEpochAtSlot(slot phase0.Slot) phase0.Epoch
35+
EstimatedSlotAtTime(time int64) phase0.Slot
36+
}
37+
3338
// SimpleSigner implements ValidatorSigner interface
3439
type SimpleSigner struct {
3540
wallet core.Wallet
3641
slashingProtector core.SlashingProtector
37-
network core.Network
42+
network network
3843
signLocks map[string]*sync.RWMutex
3944
mapLock *sync.RWMutex
4045
}
4146

4247
// NewSimpleSigner is the constructor of SimpleSigner
43-
func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network core.Network) *SimpleSigner {
48+
func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network network) *SimpleSigner {
4449
return &SimpleSigner{
4550
wallet: wallet,
4651
slashingProtector: slashingProtector,

0 commit comments

Comments
 (0)