Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions dbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
18 changes: 9 additions & 9 deletions internal/consensus/amev_preBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -56,15 +56,15 @@ 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
}

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
Expand Down
8 changes: 4 additions & 4 deletions internal/consensus/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Loading