diff --git a/dbft.go b/dbft.go index 26639e5a..c97c0166 100644 --- a/dbft.go +++ b/dbft.go @@ -233,7 +233,7 @@ func (d *DBFT[H]) onTimeout(height uint32, view byte, force bool) { d.unsubscribeFromTransactions() return } - if !d.txSubscriptionOn && len(d.Config.GetVerified()) == 0 { + if !d.txSubscriptionOn && len(d.GetVerified()) == 0 { d.subscribeForTransactions() delay := d.maxTimePerBlock<<1 - d.timePerBlock<<1 d.changeTimer(delay) @@ -319,7 +319,7 @@ func (d *DBFT[H]) OnReceive(msg ConsensusPayload[H]) { func (d *DBFT[H]) onPrepareRequest(msg ConsensusPayload[H]) { // ignore prepareRequest if we had already received it or // are in process of changing view - if d.RequestSentOrReceived() { //|| (d.ViewChanging() && !d.MoreThanFNodesCommittedOrLost()) { + if d.RequestSentOrReceived() { // || (d.ViewChanging() && !d.MoreThanFNodesCommittedOrLost()) { d.Logger.Debug("ignoring PrepareRequest", zap.Bool("sor", d.RequestSentOrReceived()), zap.Bool("viewChanging", d.ViewChanging()), @@ -390,13 +390,13 @@ func (d *DBFT[H]) processMissingTx() { func (d *DBFT[H]) createAndCheckBlock() bool { var blockOK bool if d.isAntiMEVExtensionEnabled() { - b := d.Context.CreatePreBlock() + b := d.CreatePreBlock() blockOK = d.VerifyPreBlock(b) if !blockOK { d.Logger.Warn("proposed preBlock fails verification") } } else { - b := d.Context.CreateBlock() + b := d.CreateBlock() blockOK = d.VerifyBlock(b) if !blockOK { d.Logger.Warn("proposed block fails verification") @@ -705,7 +705,7 @@ func (d *DBFT[H]) onRecoveryMessage(msg ConsensusPayload[H]) { } } - if msg.ViewNumber() == d.ViewNumber && !(d.ViewChanging() && !d.MoreThanFNodesCommittedOrLost()) && !d.CommitSent() && (!d.isAntiMEVExtensionEnabled() || !d.PreCommitSent()) { + if msg.ViewNumber() == d.ViewNumber && (!d.ViewChanging() || d.MoreThanFNodesCommittedOrLost()) && !d.CommitSent() && (!d.isAntiMEVExtensionEnabled() || !d.PreCommitSent()) { if !d.RequestSentOrReceived() { prepReq := recovery.GetPrepareRequest(msg, d.Validators, uint16(d.PrimaryIndex)) if prepReq != nil { diff --git a/dbft_test.go b/dbft_test.go index efab9f4c..a151a48e 100644 --- a/dbft_test.go +++ b/dbft_test.go @@ -590,13 +590,13 @@ func TestDBFT_Invalid(t *testing.T) { d, err := dbft.New(opts...) require.NoError(t, err) require.NotNil(t, d) - require.NotNil(t, d.Config.RequestTx) - require.NotNil(t, d.Config.GetTx) - require.NotNil(t, d.Config.GetVerified) - require.NotNil(t, d.Config.VerifyBlock) - require.NotNil(t, d.Config.Broadcast) - require.NotNil(t, d.Config.ProcessBlock) - require.NotNil(t, d.Config.GetBlock) + require.NotNil(t, d.RequestTx) + require.NotNil(t, d.GetTx) + require.NotNil(t, d.GetVerified) + require.NotNil(t, d.VerifyBlock) + require.NotNil(t, d.Broadcast) + require.NotNil(t, d.ProcessBlock) + require.NotNil(t, d.GetBlock) require.NotNil(t, d.Config.WatchOnly) }) } diff --git a/internal/consensus/amev_preBlock.go b/internal/consensus/amev_preBlock.go index 23ee7331..e74faa5e 100644 --- a/internal/consensus/amev_preBlock.go +++ b/internal/consensus/amev_preBlock.go @@ -24,25 +24,25 @@ var _ dbft.PreBlock[crypto.Uint256] = new(preBlock) // NewPreBlock returns new preBlock. func NewPreBlock(timestamp uint64, index uint32, prevHash crypto.Uint256, nonce uint64, txHashes []crypto.Uint256) dbft.PreBlock[crypto.Uint256] { pre := new(preBlock) - pre.base.Timestamp = uint32(timestamp / 1000000000) - pre.base.Index = index + pre.Timestamp = uint32(timestamp / 1000000000) + pre.Index = index // NextConsensus and Version information is not provided by dBFT context, // these are implementation-specific fields, and thus, should be managed outside the // dBFT library. For simulation simplicity, let's assume that these fields are filled // by every CN separately and is not verified. - pre.base.NextConsensus = crypto.Uint160{1, 2, 3} - pre.base.Version = 0 + pre.NextConsensus = crypto.Uint160{1, 2, 3} + pre.Version = 0 - pre.base.PrevHash = prevHash - pre.base.ConsensusData = nonce + pre.PrevHash = prevHash + pre.ConsensusData = nonce // Canary default value. pre.data = 0xff if len(txHashes) != 0 { mt := merkle.NewMerkleTree(txHashes...) - pre.base.MerkleRoot = mt.Root().Hash + pre.MerkleRoot = mt.Root().Hash } return pre } @@ -56,7 +56,7 @@ func (pre *preBlock) Data() []byte { func (pre *preBlock) SetData(_ dbft.PrivateKey) error { // Just an artificial rule for data construction, it can be anything, and in Neo X // it will be decrypted transactions fragments. - pre.data = pre.base.Index + pre.data = pre.Index return nil } @@ -64,7 +64,7 @@ func (pre *preBlock) Verify(_ dbft.PublicKey, data []byte) error { if len(data) != 4 { return errors.New("invalid data len") } - if binary.BigEndian.Uint32(data) != pre.base.Index { // Just an artificial verification rule, and for NeoX it should be decrypted transactions fragments verification. + if binary.BigEndian.Uint32(data) != pre.Index { // Just an artificial verification rule, and for NeoX it should be decrypted transactions fragments verification. return errors.New("invalid data") } return nil diff --git a/internal/consensus/block.go b/internal/consensus/block.go index 1624b221..fdff9c1c 100644 --- a/internal/consensus/block.go +++ b/internal/consensus/block.go @@ -68,18 +68,18 @@ func (b *neoBlock) SetTransactions(txx []dbft.Transaction[crypto.Uint256]) { // NewBlock returns new block. func NewBlock(timestamp uint64, index uint32, prevHash crypto.Uint256, nonce uint64, txHashes []crypto.Uint256) dbft.Block[crypto.Uint256] { block := new(neoBlock) - block.base.Timestamp = uint32(timestamp / 1000000000) + block.Timestamp = uint32(timestamp / 1000000000) block.base.Index = index // NextConsensus and Version information is not provided by dBFT context, // these are implementation-specific fields, and thus, should be managed outside the // dBFT library. For simulation simplicity, let's assume that these fields are filled // by every CN separately and is not verified. - block.base.NextConsensus = crypto.Uint160{1, 2, 3} - block.base.Version = 0 + block.NextConsensus = crypto.Uint160{1, 2, 3} + block.Version = 0 block.base.PrevHash = prevHash - block.base.ConsensusData = nonce + block.ConsensusData = nonce if len(txHashes) != 0 { mt := merkle.NewMerkleTree(txHashes...) diff --git a/send.go b/send.go index 9fcfcb8f..6c40d952 100644 --- a/send.go +++ b/send.go @@ -190,7 +190,7 @@ func (d *DBFT[H]) sendRecoveryRequest() { d.processMissingTx() } req := d.NewRecoveryRequest(uint64(d.Timer.Now().UnixNano())) - d.broadcast(d.Config.NewConsensusPayload(&d.Context, RecoveryRequestType, req)) + d.broadcast(d.NewConsensusPayload(&d.Context, RecoveryRequestType, req)) } func (c *Context[H]) makeRecoveryMessage() ConsensusPayload[H] {