Skip to content

Commit

Permalink
dbft: remove version from context
Browse files Browse the repository at this point in the history
Version context field is always set to 0. There is no API to change
Version in dBFT context. Given a possibility of Block version change, we
either need to introduce this Version initializer or need to move
Version handling out of dBFT. The latter case is chosen, because in this
case block/PrepareRequest version can be handled directly by node
depending on block index fetched from dBFT context.

Also remove Version() block API, it's unused.

A part of #84.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Mar 6, 2024
1 parent c283b80 commit cd752cc
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
2 changes: 0 additions & 2 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package dbft
type Block[H Hash] interface {
// Hash returns block hash.
Hash() H

Version() uint32
// PrevHash returns previous block hash.
PrevHash() H
// MerkleRoot returns a merkle root of the transaction hashes.
Expand Down
1 change: 0 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Context[H Hash] struct {
MyIndex int
// PrimaryIndex is an index of the primary node in the current epoch.
PrimaryIndex uint
Version uint32

// PrevHash is a hash of the previous block.
PrevHash H
Expand Down
2 changes: 1 addition & 1 deletion dbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ func newBlockFromContext(ctx *dbft.Context[crypto.Uint256]) dbft.Block[crypto.Ui
if ctx.TransactionHashes == nil {
return nil
}
block := block.NewBlock(ctx.Timestamp, ctx.BlockIndex, ctx.PrevHash, ctx.Version, ctx.Nonce, ctx.TransactionHashes)
block := block.NewBlock(ctx.Timestamp, ctx.BlockIndex, ctx.PrevHash, ctx.Nonce, ctx.TransactionHashes)
return block
}

Expand Down
18 changes: 8 additions & 10 deletions internal/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ type (
}
)

// Version implements Block interface.
func (b neoBlock) Version() uint32 {
return b.base.Version
}

// PrevHash implements Block interface.
func (b *neoBlock) PrevHash() crypto.Uint256 {
return b.base.PrevHash
Expand Down Expand Up @@ -73,16 +68,19 @@ func (b *neoBlock) SetTransactions(txx []dbft.Transaction[crypto.Uint256]) {
}

// NewBlock returns new block.
func NewBlock(timestamp uint64, index uint32, prevHash crypto.Uint256, version uint32, nonce uint64, txHashes []crypto.Uint256) dbft.Block[crypto.Uint256] {
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.base.Index = index
// NextConsensus information is not provided by dBFT context, it's an implementation-specific field,
// and thus, should be managed outside the dBFT library. For simulation simplicity, let's assume
// that NextConsensus is filled by every CN separately and is not verified.

// 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.base.PrevHash = prevHash
block.base.Version = version
block.base.ConsensusData = nonce

if len(txHashes) != 0 {
Expand Down
3 changes: 0 additions & 3 deletions internal/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ func TestNeoBlock_Setters(t *testing.T) {
b.consensusData = 123
assert.EqualValues(t, 123, b.ConsensusData())

b.base.Version = 42
assert.EqualValues(t, 42, b.Version())

b.base.PrevHash = crypto.Uint256{3, 7}
assert.Equal(t, crypto.Uint256{3, 7}, b.PrevHash())

Expand Down
2 changes: 1 addition & 1 deletion internal/simulation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func newBlockFromContext(ctx *dbft.Context[crypto.Uint256]) dbft.Block[crypto.Ui
if ctx.TransactionHashes == nil {
return nil
}
block := block.NewBlock(ctx.Timestamp, ctx.BlockIndex, ctx.PrevHash, ctx.Version, ctx.Nonce, ctx.TransactionHashes)
block := block.NewBlock(ctx.Timestamp, ctx.BlockIndex, ctx.PrevHash, ctx.Nonce, ctx.TransactionHashes)
return block
}

Expand Down

0 comments on commit cd752cc

Please sign in to comment.