diff --git a/config.go b/config.go index 5a6610e2..d0b3f316 100644 --- a/config.go +++ b/config.go @@ -70,7 +70,7 @@ type Config[H Hash, A Address] struct { // NewCommit is a constructor for payload.Commit. NewCommit func(signature []byte) Commit // NewRecoveryRequest is a constructor for payload.RecoveryRequest. - NewRecoveryRequest func() RecoveryRequest + NewRecoveryRequest func(ts uint64) RecoveryRequest // NewRecoveryMessage is a constructor for payload.RecoveryMessage. NewRecoveryMessage func() RecoveryMessage[H, A] // VerifyPrepareRequest can perform external payload verification and returns true iff it was successful. @@ -334,7 +334,7 @@ func WithNewCommit[H Hash, A Address](f func([]byte) Commit) func(config *Config } // WithNewRecoveryRequest sets NewRecoveryRequest. -func WithNewRecoveryRequest[H Hash, A Address](f func() RecoveryRequest) func(config *Config[H, A]) { +func WithNewRecoveryRequest[H Hash, A Address](f func(ts uint64) RecoveryRequest) func(config *Config[H, A]) { return func(cfg *Config[H, A]) { cfg.NewRecoveryRequest = f } diff --git a/dbft_test.go b/dbft_test.go index a6f59720..abd7a056 100644 --- a/dbft_test.go +++ b/dbft_test.go @@ -489,7 +489,7 @@ func TestDBFT_Invalid(t *testing.T) { require.Nil(t, dbft.New(opts...)) }) - opts = append(opts, dbft.WithNewRecoveryRequest[crypto.Uint256, crypto.Uint160](func() dbft.RecoveryRequest { + opts = append(opts, dbft.WithNewRecoveryRequest[crypto.Uint256, crypto.Uint160](func(uint64) dbft.RecoveryRequest { return nil })) t.Run("without NewRecoveryMessage", func(t *testing.T) { @@ -738,7 +738,7 @@ func (s testState) getChangeView(from uint16, view byte) Payload { } func (s testState) getRecoveryRequest(from uint16) Payload { - p := payload.NewConsensusPayload(dbft.RecoveryRequestType, s.currHeight+1, from, 0, payload.NewRecoveryRequest()) + p := payload.NewConsensusPayload(dbft.RecoveryRequestType, s.currHeight+1, from, 0, payload.NewRecoveryRequest(0)) return p } diff --git a/internal/payload/constructors.go b/internal/payload/constructors.go index 0adb4e86..68f19fe7 100644 --- a/internal/payload/constructors.go +++ b/internal/payload/constructors.go @@ -51,8 +51,10 @@ func NewCommit(signature []byte) dbft.Commit { } // NewRecoveryRequest returns minimal RecoveryRequest implementation. -func NewRecoveryRequest() dbft.RecoveryRequest { - return new(recoveryRequest) +func NewRecoveryRequest(ts uint64) dbft.RecoveryRequest { + return &recoveryRequest{ + timestamp: nanoSecToSec(ts), + } } // NewRecoveryMessage returns minimal RecoveryMessage implementation. diff --git a/internal/payload/message_test.go b/internal/payload/message_test.go index f0a51bad..59fc44a6 100644 --- a/internal/payload/message_test.go +++ b/internal/payload/message_test.go @@ -161,9 +161,8 @@ func TestPayload_Setters(t *testing.T) { }) t.Run("RecoveryRequest", func(t *testing.T) { - r := NewRecoveryRequest() + r := NewRecoveryRequest(secToNanoSec(321)) - r.SetTimestamp(secToNanoSec(321)) require.EqualValues(t, secToNanoSec(321), r.Timestamp()) }) diff --git a/internal/payload/recovery_request.go b/internal/payload/recovery_request.go index 5fe78446..43576139 100644 --- a/internal/payload/recovery_request.go +++ b/internal/payload/recovery_request.go @@ -40,8 +40,3 @@ func (m *recoveryRequest) DecodeBinary(r *gob.Decoder) error { func (m *recoveryRequest) Timestamp() uint64 { return secToNanoSec(m.timestamp) } - -// SetTimestamp implements RecoveryRequest interface. -func (m *recoveryRequest) SetTimestamp(ts uint64) { - m.timestamp = nanoSecToSec(ts) -} diff --git a/recovery_request.go b/recovery_request.go index 08d74137..232b9cf9 100644 --- a/recovery_request.go +++ b/recovery_request.go @@ -4,6 +4,4 @@ package dbft type RecoveryRequest interface { // Timestamp returns this message's timestamp. Timestamp() uint64 - // SetTimestamp sets this message's timestamp. - SetTimestamp(ts uint64) } diff --git a/send.go b/send.go index 675e9d37..4e32149a 100644 --- a/send.go +++ b/send.go @@ -131,8 +131,7 @@ func (d *DBFT[H, A]) sendRecoveryRequest() { if d.RequestSentOrReceived() && !d.hasAllTransactions() { d.processMissingTx() } - req := d.NewRecoveryRequest() - req.SetTimestamp(uint64(d.Timer.Now().UnixNano())) + req := d.NewRecoveryRequest(uint64(d.Timer.Now().UnixNano())) d.broadcast(d.Config.NewConsensusPayload(&d.Context, RecoveryRequestType, req)) }