diff --git a/signer/far_future_protection.go b/signer/far_future_protection.go index 8b21743f..36ef7fdd 100644 --- a/signer/far_future_protection.go +++ b/signer/far_future_protection.go @@ -4,8 +4,6 @@ import ( "time" "github.com/attestantio/go-eth2-client/spec/phase0" - - "github.com/ssvlabs/eth2-key-manager/core" ) // FarFutureMaxValidEpoch is the max epoch of far future signing @@ -13,13 +11,13 @@ var FarFutureMaxValidEpoch = int64(time.Minute.Seconds() * 20) // IsValidFarFutureEpoch prevents far into the future signing request, verify a slot is within the current epoch // https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/validator.md#protection-best-practices -func IsValidFarFutureEpoch(network core.Network, epoch phase0.Epoch) bool { +func IsValidFarFutureEpoch(network network, epoch phase0.Epoch) bool { maxValidEpoch := network.EstimatedEpochAtSlot(network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch)) return epoch <= maxValidEpoch } // IsValidFarFutureSlot returns true if the given slot is valid -func IsValidFarFutureSlot(network core.Network, slot phase0.Slot) bool { +func IsValidFarFutureSlot(network network, slot phase0.Slot) bool { maxValidSlot := network.EstimatedSlotAtTime(time.Now().Unix() + FarFutureMaxValidEpoch) return slot <= maxValidSlot } diff --git a/signer/validator_signer.go b/signer/validator_signer.go index 29468089..63e4977c 100644 --- a/signer/validator_signer.go +++ b/signer/validator_signer.go @@ -30,17 +30,22 @@ type ValidatorSigner interface { SignBLSToExecutionChange(blsToExecutionChange *capella.BLSToExecutionChange, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error) } +type network interface { + EstimatedEpochAtSlot(slot phase0.Slot) phase0.Epoch + EstimatedSlotAtTime(time int64) phase0.Slot +} + // SimpleSigner implements ValidatorSigner interface type SimpleSigner struct { wallet core.Wallet slashingProtector core.SlashingProtector - network core.Network + network network signLocks map[string]*sync.RWMutex mapLock *sync.RWMutex } // NewSimpleSigner is the constructor of SimpleSigner -func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network core.Network) *SimpleSigner { +func NewSimpleSigner(wallet core.Wallet, slashingProtector core.SlashingProtector, network network) *SimpleSigner { return &SimpleSigner{ wallet: wallet, slashingProtector: slashingProtector,