diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b40167a6..3877368e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,5 +42,5 @@ jobs: - name: Run simulation run: | - cd ./simulation + cd ./internal/simulation go run main.go diff --git a/dbft_test.go b/dbft_test.go index 336c1a4e..4aa9511d 100644 --- a/dbft_test.go +++ b/dbft_test.go @@ -7,9 +7,9 @@ import ( "time" "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/block" - "github.com/nspcc-dev/dbft/crypto" - "github.com/nspcc-dev/dbft/payload" + "github.com/nspcc-dev/dbft/internal/block" + "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/nspcc-dev/dbft/internal/payload" "github.com/nspcc-dev/dbft/timer" "github.com/stretchr/testify/require" "go.uber.org/zap" diff --git a/helpers_test.go b/helpers_test.go index 7a0cefa7..f1101e04 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" - "github.com/nspcc-dev/dbft/payload" + "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/nspcc-dev/dbft/internal/payload" "github.com/stretchr/testify/require" ) diff --git a/block/block.go b/internal/block/block.go similarity index 97% rename from block/block.go rename to internal/block/block.go index d52fbac0..19940e7d 100644 --- a/block/block.go +++ b/internal/block/block.go @@ -3,10 +3,10 @@ package block import ( "bytes" "encoding/gob" - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" - "github.com/nspcc-dev/dbft/merkle" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/nspcc-dev/dbft/internal/merkle" ) type ( diff --git a/block/block_test.go b/internal/block/block_test.go similarity index 75% rename from block/block_test.go rename to internal/block/block_test.go index 6e42c1ff..a49bc759 100644 --- a/block/block_test.go +++ b/internal/block/block_test.go @@ -6,10 +6,11 @@ import ( "encoding/binary" "encoding/gob" "errors" - "github.com/nspcc-dev/dbft" "testing" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + crypto2 "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -17,9 +18,9 @@ import ( func TestNeoBlock_Setters(t *testing.T) { b := new(neoBlock) - require.Equal(t, crypto.Uint256{}, b.Hash()) + require.Equal(t, crypto2.Uint256{}, b.Hash()) - txs := []dbft.Transaction[crypto.Uint256]{testTx(1), testTx(2)} + txs := []dbft.Transaction[crypto2.Uint256]{testTx(1), testTx(2)} b.SetTransactions(txs) assert.Equal(t, txs, b.Transactions()) @@ -29,14 +30,14 @@ func TestNeoBlock_Setters(t *testing.T) { b.base.Version = 42 assert.EqualValues(t, 42, b.Version()) - b.base.NextConsensus = crypto.Uint160{1} - assert.Equal(t, crypto.Uint160{1}, b.NextConsensus()) + b.base.NextConsensus = crypto2.Uint160{1} + assert.Equal(t, crypto2.Uint160{1}, b.NextConsensus()) - b.base.PrevHash = crypto.Uint256{3, 7} - assert.Equal(t, crypto.Uint256{3, 7}, b.PrevHash()) + b.base.PrevHash = crypto2.Uint256{3, 7} + assert.Equal(t, crypto2.Uint256{3, 7}, b.PrevHash()) - b.base.MerkleRoot = crypto.Uint256{13} - assert.Equal(t, crypto.Uint256{13}, b.MerkleRoot()) + b.base.MerkleRoot = crypto2.Uint256{13} + assert.Equal(t, crypto2.Uint256{13}, b.MerkleRoot()) b.base.Timestamp = 1234 // 1234s -> 1234000000000ns @@ -59,7 +60,7 @@ func TestNeoBlock_Setters(t *testing.T) { }) t.Run("hash does not change after signature", func(t *testing.T) { - priv, pub := crypto.Generate(rand.Reader) + priv, pub := crypto2.Generate(rand.Reader) require.NotNil(t, priv) require.NotNil(t, pub) @@ -85,7 +86,7 @@ func (t testKey) Sign([]byte) ([]byte, error) { type testTx uint64 -func (tx testTx) Hash() (h crypto.Uint256) { +func (tx testTx) Hash() (h crypto2.Uint256) { binary.LittleEndian.PutUint64(h[:], uint64(tx)) return } diff --git a/crypto/crypto.go b/internal/crypto/crypto.go similarity index 99% rename from crypto/crypto.go rename to internal/crypto/crypto.go index 2a279828..44815f50 100644 --- a/crypto/crypto.go +++ b/internal/crypto/crypto.go @@ -1,8 +1,9 @@ package crypto import ( - "github.com/nspcc-dev/dbft" "io" + + "github.com/nspcc-dev/dbft" ) type suiteType byte diff --git a/crypto/crypto_test.go b/internal/crypto/crypto_test.go similarity index 100% rename from crypto/crypto_test.go rename to internal/crypto/crypto_test.go diff --git a/crypto/ecdsa.go b/internal/crypto/ecdsa.go similarity index 99% rename from crypto/ecdsa.go rename to internal/crypto/ecdsa.go index c0f7e830..d663016d 100644 --- a/crypto/ecdsa.go +++ b/internal/crypto/ecdsa.go @@ -5,10 +5,11 @@ import ( "crypto/elliptic" "crypto/sha256" "errors" - "github.com/nspcc-dev/dbft" "io" "math/big" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/rfc6979" ) diff --git a/crypto/ecdsa_test.go b/internal/crypto/ecdsa_test.go similarity index 100% rename from crypto/ecdsa_test.go rename to internal/crypto/ecdsa_test.go diff --git a/crypto/hash.go b/internal/crypto/hash.go similarity index 100% rename from crypto/hash.go rename to internal/crypto/hash.go diff --git a/crypto/hash_test.go b/internal/crypto/hash_test.go similarity index 100% rename from crypto/hash_test.go rename to internal/crypto/hash_test.go diff --git a/merkle/merkle_tree.go b/internal/merkle/merkle_tree.go similarity index 97% rename from merkle/merkle_tree.go rename to internal/merkle/merkle_tree.go index 88bc8939..5d6bb31e 100644 --- a/merkle/merkle_tree.go +++ b/internal/merkle/merkle_tree.go @@ -1,7 +1,7 @@ package merkle import ( - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft/internal/crypto" ) type ( diff --git a/merkle/merkle_tree_test.go b/internal/merkle/merkle_tree_test.go similarity index 96% rename from merkle/merkle_tree_test.go rename to internal/merkle/merkle_tree_test.go index 1fc1240c..99706b16 100644 --- a/merkle/merkle_tree_test.go +++ b/internal/merkle/merkle_tree_test.go @@ -5,7 +5,7 @@ import ( "encoding/hex" "testing" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft/internal/crypto" "github.com/stretchr/testify/require" ) diff --git a/payload/change_view.go b/internal/payload/change_view.go similarity index 99% rename from payload/change_view.go rename to internal/payload/change_view.go index 036b53a0..1e5d0693 100644 --- a/payload/change_view.go +++ b/internal/payload/change_view.go @@ -2,6 +2,7 @@ package payload import ( "encoding/gob" + "github.com/nspcc-dev/dbft" ) diff --git a/payload/commit.go b/internal/payload/commit.go similarity index 99% rename from payload/commit.go rename to internal/payload/commit.go index 62cca293..70e962bb 100644 --- a/payload/commit.go +++ b/internal/payload/commit.go @@ -2,6 +2,7 @@ package payload import ( "encoding/gob" + "github.com/nspcc-dev/dbft" ) diff --git a/payload/compact.go b/internal/payload/compact.go similarity index 100% rename from payload/compact.go rename to internal/payload/compact.go diff --git a/payload/consensus_message.go b/internal/payload/consensus_message.go similarity index 98% rename from payload/consensus_message.go rename to internal/payload/consensus_message.go index 139411ef..95da6329 100644 --- a/payload/consensus_message.go +++ b/internal/payload/consensus_message.go @@ -3,9 +3,10 @@ package payload import ( "bytes" "encoding/gob" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" - "github.com/nspcc-dev/dbft/crypto" "github.com/pkg/errors" ) diff --git a/payload/constructors.go b/internal/payload/constructors.go similarity index 96% rename from payload/constructors.go rename to internal/payload/constructors.go index bf1e81bd..ac1ecd0a 100644 --- a/payload/constructors.go +++ b/internal/payload/constructors.go @@ -2,7 +2,7 @@ package payload import ( "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft/internal/crypto" ) // NewConsensusPayload returns minimal ConsensusPayload implementation. diff --git a/payload/helpers.go b/internal/payload/helpers.go similarity index 100% rename from payload/helpers.go rename to internal/payload/helpers.go diff --git a/payload/message.go b/internal/payload/message.go similarity index 98% rename from payload/message.go rename to internal/payload/message.go index e07f3bb8..e7de8274 100644 --- a/payload/message.go +++ b/internal/payload/message.go @@ -3,9 +3,9 @@ package payload import ( "bytes" "encoding/gob" - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" ) type ( diff --git a/payload/message_test.go b/internal/payload/message_test.go similarity index 90% rename from payload/message_test.go rename to internal/payload/message_test.go index 22fe9f3c..9b1304c1 100644 --- a/payload/message_test.go +++ b/internal/payload/message_test.go @@ -4,10 +4,11 @@ import ( "bytes" "crypto/rand" "encoding/gob" - "github.com/nspcc-dev/dbft" "testing" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + crypto2 "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -16,7 +17,7 @@ func TestPayload_EncodeDecode(t *testing.T) { m := NewConsensusPayload().(*Payload) m.SetValidatorIndex(10) m.SetHeight(77) - m.SetPrevHash(crypto.Uint256{1}) + m.SetPrevHash(crypto2.Uint256{1}) m.SetVersion(8) m.SetViewNumber(3) @@ -25,7 +26,7 @@ func TestPayload_EncodeDecode(t *testing.T) { m.SetPayload(&prepareRequest{ nonce: 123, timestamp: 345, - transactionHashes: []crypto.Uint256{ + transactionHashes: []crypto2.Uint256{ {1, 2, 3}, {5, 6, 7}, }, @@ -38,7 +39,7 @@ func TestPayload_EncodeDecode(t *testing.T) { t.Run("PrepareResponse", func(t *testing.T) { m.SetType(dbft.PrepareResponseType) m.SetPayload(&prepareResponse{ - preparationHash: crypto.Uint256{3}, + preparationHash: crypto2.Uint256{3}, }) testEncodeDecode(t, m, new(Payload)) @@ -85,7 +86,7 @@ func TestPayload_EncodeDecode(t *testing.T) { prepareRequest: &prepareRequest{ nonce: 123, timestamp: 345, - transactionHashes: []crypto.Uint256{ + transactionHashes: []crypto2.Uint256{ {1, 2, 3}, {5, 6, 7}, }, @@ -111,22 +112,22 @@ func TestRecoveryMessage_NoPayloads(t *testing.T) { m := NewConsensusPayload().(*Payload) m.SetValidatorIndex(0) m.SetHeight(77) - m.SetPrevHash(crypto.Uint256{1}) + m.SetPrevHash(crypto2.Uint256{1}) m.SetVersion(8) m.SetViewNumber(3) m.SetPayload(&recoveryMessage{}) validators := make([]dbft.PublicKey, 1) - _, validators[0] = crypto.Generate(rand.Reader) + _, validators[0] = crypto2.Generate(rand.Reader) rec := m.GetRecoveryMessage() require.NotNil(t, rec) - var p dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160] + var p dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160] require.NotPanics(t, func() { p = rec.GetPrepareRequest(p, validators, 0) }) require.Nil(t, p) - var ps []dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160] + var ps []dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160] require.NotPanics(t, func() { ps = rec.GetPrepareResponses(p, validators) }) require.Len(t, ps, 0) @@ -188,8 +189,8 @@ func TestPayload_Setters(t *testing.T) { t.Run("RecoveryMessage", func(t *testing.T) { r := NewRecoveryMessage() - r.SetPreparationHash(&crypto.Uint256{1, 2, 3}) - require.Equal(t, &crypto.Uint256{1, 2, 3}, r.PreparationHash()) + r.SetPreparationHash(&crypto2.Uint256{1, 2, 3}) + require.Equal(t, &crypto2.Uint256{1, 2, 3}, r.PreparationHash()) }) } diff --git a/payload/prepare_request.go b/internal/payload/prepare_request.go similarity index 98% rename from payload/prepare_request.go rename to internal/payload/prepare_request.go index 9098cfb0..ccbab16b 100644 --- a/payload/prepare_request.go +++ b/internal/payload/prepare_request.go @@ -2,9 +2,9 @@ package payload import ( "encoding/gob" - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" ) type ( diff --git a/payload/prepare_response.go b/internal/payload/prepare_response.go similarity index 96% rename from payload/prepare_response.go rename to internal/payload/prepare_response.go index f66f0c97..fb49bfe5 100644 --- a/payload/prepare_response.go +++ b/internal/payload/prepare_response.go @@ -2,9 +2,9 @@ package payload import ( "encoding/gob" - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" ) type ( diff --git a/payload/recovery_message.go b/internal/payload/recovery_message.go similarity index 99% rename from payload/recovery_message.go rename to internal/payload/recovery_message.go index 1491aa0f..870f402c 100644 --- a/payload/recovery_message.go +++ b/internal/payload/recovery_message.go @@ -3,9 +3,9 @@ package payload import ( "encoding/gob" "errors" - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" + "github.com/nspcc-dev/dbft" + "github.com/nspcc-dev/dbft/internal/crypto" ) type ( diff --git a/payload/recovery_request.go b/internal/payload/recovery_request.go similarity index 99% rename from payload/recovery_request.go rename to internal/payload/recovery_request.go index 0cc73930..5fe78446 100644 --- a/payload/recovery_request.go +++ b/internal/payload/recovery_request.go @@ -2,6 +2,7 @@ package payload import ( "encoding/gob" + "github.com/nspcc-dev/dbft" ) diff --git a/simulation/main.go b/internal/simulation/main.go similarity index 63% rename from simulation/main.go rename to internal/simulation/main.go index bf776ec5..92a8d90e 100644 --- a/simulation/main.go +++ b/internal/simulation/main.go @@ -7,7 +7,6 @@ import ( "errors" "flag" "fmt" - "github.com/nspcc-dev/dbft/block" "net/http" "net/http/pprof" "os" @@ -17,9 +16,11 @@ import ( "syscall" "time" + "github.com/nspcc-dev/dbft/internal/block" + crypto2 "github.com/nspcc-dev/dbft/internal/crypto" + "github.com/nspcc-dev/dbft/internal/payload" + "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/dbft/crypto" - "github.com/nspcc-dev/dbft/payload" "github.com/spaolacci/murmur3" "go.uber.org/zap" ) @@ -27,8 +28,8 @@ import ( type ( simNode struct { id int - d *dbft.DBFT[crypto.Uint256, crypto.Uint160] - messages chan dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160] + d *dbft.DBFT[crypto2.Uint256, crypto2.Uint160] + messages chan dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160] key dbft.PrivateKey pub dbft.PublicKey pool *memPool @@ -36,7 +37,7 @@ type ( log *zap.Logger height uint32 - lastHash crypto.Uint256 + lastHash crypto2.Uint256 validators []dbft.PublicKey } ) @@ -110,7 +111,7 @@ func initNodes(nodes []*simNode, log *zap.Logger) { } } -func newBlockFromContext(ctx *dbft.Context[crypto.Uint256, crypto.Uint160]) dbft.Block[crypto.Uint256, crypto.Uint160] { +func newBlockFromContext(ctx *dbft.Context[crypto2.Uint256, crypto2.Uint160]) dbft.Block[crypto2.Uint256, crypto2.Uint160] { if ctx.TransactionHashes == nil { return nil } @@ -120,7 +121,7 @@ func newBlockFromContext(ctx *dbft.Context[crypto.Uint256, crypto.Uint160]) dbft // defaultNewConsensusPayload is default function for creating // consensus payload of specific type. -func defaultNewConsensusPayload(c *dbft.Context[crypto.Uint256, crypto.Uint160], t dbft.MessageType, msg any) dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160] { +func defaultNewConsensusPayload(c *dbft.Context[crypto2.Uint256, crypto2.Uint160], t dbft.MessageType, msg any) dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160] { cp := payload.NewConsensusPayload() cp.SetHeight(c.BlockIndex) cp.SetValidatorIndex(uint16(c.MyIndex)) @@ -132,10 +133,10 @@ func defaultNewConsensusPayload(c *dbft.Context[crypto.Uint256, crypto.Uint160], } func initSimNode(nodes []*simNode, i int, log *zap.Logger) error { - key, pub := crypto.Generate(rand.Reader) + key, pub := crypto2.Generate(rand.Reader) nodes[i] = &simNode{ id: i, - messages: make(chan dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160], defaultChanSize), + messages: make(chan dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160], defaultChanSize), key: key, pub: pub, pool: newMemoryPool(), @@ -143,29 +144,29 @@ func initSimNode(nodes []*simNode, i int, log *zap.Logger) error { cluster: nodes, } - nodes[i].d = dbft.New[crypto.Uint256, crypto.Uint160]( - dbft.WithLogger[crypto.Uint256, crypto.Uint160](nodes[i].log), - dbft.WithSecondsPerBlock[crypto.Uint256, crypto.Uint160](time.Second*5), - dbft.WithKeyPair[crypto.Uint256, crypto.Uint160](key, pub), - dbft.WithGetTx[crypto.Uint256, crypto.Uint160](nodes[i].pool.Get), - dbft.WithGetVerified[crypto.Uint256, crypto.Uint160](nodes[i].pool.GetVerified), - dbft.WithBroadcast[crypto.Uint256, crypto.Uint160](nodes[i].Broadcast), - dbft.WithProcessBlock[crypto.Uint256, crypto.Uint160](nodes[i].ProcessBlock), - dbft.WithCurrentHeight[crypto.Uint256, crypto.Uint160](nodes[i].CurrentHeight), - dbft.WithCurrentBlockHash[crypto.Uint256, crypto.Uint160](nodes[i].CurrentBlockHash), - dbft.WithGetValidators[crypto.Uint256, crypto.Uint160](nodes[i].GetValidators), - dbft.WithVerifyPrepareRequest[crypto.Uint256, crypto.Uint160](nodes[i].VerifyPayload), - dbft.WithVerifyPrepareResponse[crypto.Uint256, crypto.Uint160](nodes[i].VerifyPayload), - - dbft.WithNewBlockFromContext[crypto.Uint256, crypto.Uint160](newBlockFromContext), - dbft.WithGetConsensusAddress[crypto.Uint256, crypto.Uint160](func(...dbft.PublicKey) crypto.Uint160 { return crypto.Uint160{} }), - dbft.WithNewConsensusPayload[crypto.Uint256, crypto.Uint160](defaultNewConsensusPayload), - dbft.WithNewPrepareRequest[crypto.Uint256, crypto.Uint160](payload.NewPrepareRequest), - dbft.WithNewPrepareResponse[crypto.Uint256, crypto.Uint160](payload.NewPrepareResponse), - dbft.WithNewChangeView[crypto.Uint256, crypto.Uint160](payload.NewChangeView), - dbft.WithNewCommit[crypto.Uint256, crypto.Uint160](payload.NewCommit), - dbft.WithNewRecoveryMessage[crypto.Uint256, crypto.Uint160](payload.NewRecoveryMessage), - dbft.WithNewRecoveryRequest[crypto.Uint256, crypto.Uint160](payload.NewRecoveryRequest), + nodes[i].d = dbft.New[crypto2.Uint256, crypto2.Uint160]( + dbft.WithLogger[crypto2.Uint256, crypto2.Uint160](nodes[i].log), + dbft.WithSecondsPerBlock[crypto2.Uint256, crypto2.Uint160](time.Second*5), + dbft.WithKeyPair[crypto2.Uint256, crypto2.Uint160](key, pub), + dbft.WithGetTx[crypto2.Uint256, crypto2.Uint160](nodes[i].pool.Get), + dbft.WithGetVerified[crypto2.Uint256, crypto2.Uint160](nodes[i].pool.GetVerified), + dbft.WithBroadcast[crypto2.Uint256, crypto2.Uint160](nodes[i].Broadcast), + dbft.WithProcessBlock[crypto2.Uint256, crypto2.Uint160](nodes[i].ProcessBlock), + dbft.WithCurrentHeight[crypto2.Uint256, crypto2.Uint160](nodes[i].CurrentHeight), + dbft.WithCurrentBlockHash[crypto2.Uint256, crypto2.Uint160](nodes[i].CurrentBlockHash), + dbft.WithGetValidators[crypto2.Uint256, crypto2.Uint160](nodes[i].GetValidators), + dbft.WithVerifyPrepareRequest[crypto2.Uint256, crypto2.Uint160](nodes[i].VerifyPayload), + dbft.WithVerifyPrepareResponse[crypto2.Uint256, crypto2.Uint160](nodes[i].VerifyPayload), + + dbft.WithNewBlockFromContext[crypto2.Uint256, crypto2.Uint160](newBlockFromContext), + dbft.WithGetConsensusAddress[crypto2.Uint256, crypto2.Uint160](func(...dbft.PublicKey) crypto2.Uint160 { return crypto2.Uint160{} }), + dbft.WithNewConsensusPayload[crypto2.Uint256, crypto2.Uint160](defaultNewConsensusPayload), + dbft.WithNewPrepareRequest[crypto2.Uint256, crypto2.Uint160](payload.NewPrepareRequest), + dbft.WithNewPrepareResponse[crypto2.Uint256, crypto2.Uint160](payload.NewPrepareResponse), + dbft.WithNewChangeView[crypto2.Uint256, crypto2.Uint160](payload.NewChangeView), + dbft.WithNewCommit[crypto2.Uint256, crypto2.Uint160](payload.NewCommit), + dbft.WithNewRecoveryMessage[crypto2.Uint256, crypto2.Uint160](payload.NewRecoveryMessage), + dbft.WithNewRecoveryRequest[crypto2.Uint256, crypto2.Uint160](payload.NewRecoveryRequest), ) if nodes[i].d == nil { @@ -198,7 +199,7 @@ func sortValidators(pubs []dbft.PublicKey) { }) } -func (n *simNode) Broadcast(m dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160]) { +func (n *simNode) Broadcast(m dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160]) { for i, node := range n.cluster { if i != n.id { select { @@ -210,15 +211,15 @@ func (n *simNode) Broadcast(m dbft.ConsensusPayload[crypto.Uint256, crypto.Uint1 } } -func (n *simNode) CurrentHeight() uint32 { return n.height } -func (n *simNode) CurrentBlockHash() crypto.Uint256 { return n.lastHash } +func (n *simNode) CurrentHeight() uint32 { return n.height } +func (n *simNode) CurrentBlockHash() crypto2.Uint256 { return n.lastHash } // GetValidators always returns the same list of validators. -func (n *simNode) GetValidators(...dbft.Transaction[crypto.Uint256]) []dbft.PublicKey { +func (n *simNode) GetValidators(...dbft.Transaction[crypto2.Uint256]) []dbft.PublicKey { return n.validators } -func (n *simNode) ProcessBlock(b dbft.Block[crypto.Uint256, crypto.Uint160]) { +func (n *simNode) ProcessBlock(b dbft.Block[crypto2.Uint256, crypto2.Uint160]) { n.d.Logger.Debug("received block", zap.Uint32("height", b.Index())) for _, tx := range b.Transactions() { @@ -230,7 +231,7 @@ func (n *simNode) ProcessBlock(b dbft.Block[crypto.Uint256, crypto.Uint160]) { } // VerifyPrepareRequest verifies that payload was received from a good validator. -func (n *simNode) VerifyPayload(p dbft.ConsensusPayload[crypto.Uint256, crypto.Uint160]) error { +func (n *simNode) VerifyPayload(p dbft.ConsensusPayload[crypto2.Uint256, crypto2.Uint160]) error { if *blocked != -1 && p.ValidatorIndex() == uint16(*blocked) { return fmt.Errorf("message from blocked validator: %d", *blocked) } @@ -250,9 +251,9 @@ func (n *simNode) addTx(count int) { type tx64 uint64 -var _ dbft.Transaction[crypto.Uint256] = (*tx64)(nil) +var _ dbft.Transaction[crypto2.Uint256] = (*tx64)(nil) -func (t *tx64) Hash() (h crypto.Uint256) { +func (t *tx64) Hash() (h crypto2.Uint256) { binary.LittleEndian.PutUint64(h[:], uint64(*t)) return } @@ -282,17 +283,17 @@ func (t *tx64) UnmarshalBinary(data []byte) error { type memPool struct { mtx *sync.RWMutex - store map[crypto.Uint256]dbft.Transaction[crypto.Uint256] + store map[crypto2.Uint256]dbft.Transaction[crypto2.Uint256] } func newMemoryPool() *memPool { return &memPool{ mtx: new(sync.RWMutex), - store: make(map[crypto.Uint256]dbft.Transaction[crypto.Uint256]), + store: make(map[crypto2.Uint256]dbft.Transaction[crypto2.Uint256]), } } -func (p *memPool) Add(tx dbft.Transaction[crypto.Uint256]) { +func (p *memPool) Add(tx dbft.Transaction[crypto2.Uint256]) { p.mtx.Lock() h := tx.Hash() @@ -303,7 +304,7 @@ func (p *memPool) Add(tx dbft.Transaction[crypto.Uint256]) { p.mtx.Unlock() } -func (p *memPool) Get(h crypto.Uint256) (tx dbft.Transaction[crypto.Uint256]) { +func (p *memPool) Get(h crypto2.Uint256) (tx dbft.Transaction[crypto2.Uint256]) { p.mtx.RLock() tx = p.store[h] p.mtx.RUnlock() @@ -311,19 +312,19 @@ func (p *memPool) Get(h crypto.Uint256) (tx dbft.Transaction[crypto.Uint256]) { return } -func (p *memPool) Delete(h crypto.Uint256) { +func (p *memPool) Delete(h crypto2.Uint256) { p.mtx.Lock() delete(p.store, h) p.mtx.Unlock() } -func (p *memPool) GetVerified() (txx []dbft.Transaction[crypto.Uint256]) { +func (p *memPool) GetVerified() (txx []dbft.Transaction[crypto2.Uint256]) { n := *txPerBlock if n == 0 { return } - txx = make([]dbft.Transaction[crypto.Uint256], 0, n) + txx = make([]dbft.Transaction[crypto2.Uint256], 0, n) for _, tx := range p.store { txx = append(txx, tx)