mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
Merge pull request #3711 from nspcc-dev/fetch-dbft
go.mod: upgrade dBFT version
This commit is contained in:
commit
7b82c759ce
11 changed files with 26 additions and 42 deletions
2
go.mod
2
go.mod
|
@ -13,7 +13,7 @@ require (
|
|||
github.com/holiman/uint256 v1.3.1
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/mr-tron/base58 v1.2.0
|
||||
github.com/nspcc-dev/dbft v0.3.0
|
||||
github.com/nspcc-dev/dbft v0.3.1
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20240830112754-291b000d1f3b
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec
|
||||
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12
|
||||
|
|
4
go.sum
4
go.sum
|
@ -136,8 +136,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
|
|||
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/nspcc-dev/dbft v0.3.0 h1:P9dFQje43sabA6w89l1OqGe1BvnO7DdHcu27w6mfnOE=
|
||||
github.com/nspcc-dev/dbft v0.3.0/go.mod h1:oFE6paSC/yfFh9mcNU6MheMGOYXK9+sPiRk3YMoz49o=
|
||||
github.com/nspcc-dev/dbft v0.3.1 h1:3qoc65CVJMtdL/627JZH+1Jz839LmdsVN52L4mlP5z8=
|
||||
github.com/nspcc-dev/dbft v0.3.1/go.mod h1:BNvJkPKTE28r+qRaAk2C3VoL2J9qzox3fvEeJbh7EWE=
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20240830112754-291b000d1f3b h1:DRG4cRqIOmI/nUPggMgR92Jxt63Lxsuz40m5QpdvYXI=
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20240830112754-291b000d1f3b/go.mod h1:d3cUseu4Asxfo9/QA/w4TtGjM0AbC9ynyab+PfH+Bso=
|
||||
github.com/nspcc-dev/hrw/v2 v2.0.1 h1:CxYUkBeJvNfMEn2lHhrV6FjY8pZPceSxXUtMVq0BUOU=
|
||||
|
|
|
@ -24,8 +24,8 @@ var _ dbft.Block[util.Uint256] = (*neoBlock)(nil)
|
|||
|
||||
// Sign implements the block.Block interface.
|
||||
func (n *neoBlock) Sign(key dbft.PrivateKey) error {
|
||||
k := key.(*privateKey)
|
||||
sig := k.PrivateKey.SignHashable(uint32(n.network), &n.Block)
|
||||
k := key.(*keys.PrivateKey)
|
||||
sig := k.SignHashable(uint32(n.network), &n.Block)
|
||||
n.signature = sig
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestNeoBlock_Sign(t *testing.T) {
|
|||
b := new(neoBlock)
|
||||
priv, _ := keys.NewPrivateKey()
|
||||
|
||||
require.NoError(t, b.Sign(&privateKey{PrivateKey: priv}))
|
||||
require.NoError(t, b.Sign(priv))
|
||||
require.NoError(t, b.Verify(priv.PublicKey(), b.Signature()))
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ func NewService(cfg Config) (Service, error) {
|
|||
dbft.WithNewRecoveryMessage[util.Uint256](srv.newRecoveryMessage),
|
||||
dbft.WithVerifyPrepareRequest[util.Uint256](srv.verifyRequest),
|
||||
dbft.WithVerifyPrepareResponse[util.Uint256](srv.verifyResponse),
|
||||
dbft.WithVerifyCommit[util.Uint256](srv.verifyCommit),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -448,7 +449,7 @@ func (s *service) getKeyPair(pubs []dbft.PublicKey) (int, dbft.PrivateKey, dbft.
|
|||
}
|
||||
}
|
||||
|
||||
return i, &privateKey{PrivateKey: acc.PrivateKey()}, acc.PublicKey()
|
||||
return i, acc.PrivateKey(), acc.PublicKey()
|
||||
}
|
||||
}
|
||||
return -1, nil, nil
|
||||
|
@ -494,7 +495,7 @@ func (s *service) OnTransaction(tx *transaction.Transaction) {
|
|||
}
|
||||
|
||||
func (s *service) broadcast(p dbft.ConsensusPayload[util.Uint256]) {
|
||||
if err := p.(*Payload).Sign(s.dbft.Priv.(*privateKey)); err != nil {
|
||||
if err := p.(*Payload).Sign(s.dbft.Priv.(*keys.PrivateKey)); err != nil {
|
||||
s.log.Warn("can't sign consensus payload", zap.Error(err))
|
||||
}
|
||||
|
||||
|
@ -614,7 +615,11 @@ func (s *service) verifyResponse(p dbft.ConsensusPayload[util.Uint256]) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) processBlock(b dbft.Block[util.Uint256]) {
|
||||
func (s *service) verifyCommit(p dbft.ConsensusPayload[util.Uint256]) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) processBlock(b dbft.Block[util.Uint256]) error {
|
||||
bb := &b.(*neoBlock).Block
|
||||
bb.Script = *(s.getBlockWitness(bb))
|
||||
|
||||
|
@ -626,6 +631,7 @@ func (s *service) processBlock(b dbft.Block[util.Uint256]) {
|
|||
}
|
||||
}
|
||||
s.postBlock(bb)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) postBlock(b *coreb.Block) {
|
||||
|
|
|
@ -532,9 +532,9 @@ func (bq testBlockQueuer) PutBlock(b *coreb.Block) error {
|
|||
return bq.bc.AddBlock(b)
|
||||
}
|
||||
|
||||
func getTestValidator(i int) (*privateKey, *keys.PublicKey) {
|
||||
func getTestValidator(i int) (*keys.PrivateKey, *keys.PublicKey) {
|
||||
key := testchain.PrivateKey(i)
|
||||
return &privateKey{PrivateKey: key}, key.PublicKey()
|
||||
return key, key.PublicKey()
|
||||
}
|
||||
|
||||
func newSingleTestChain(t *testing.T) *core.Blockchain {
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/dbft"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
)
|
||||
|
||||
// privateKey is a wrapper around keys.PrivateKey
|
||||
// which implements the crypto.PrivateKey interface.
|
||||
type privateKey struct {
|
||||
*keys.PrivateKey
|
||||
}
|
||||
|
||||
var _ dbft.PrivateKey = &privateKey{}
|
||||
|
||||
// Sign implements the dbft's crypto.PrivateKey interface.
|
||||
func (p *privateKey) Sign(data []byte) ([]byte, error) {
|
||||
return p.PrivateKey.Sign(data), nil
|
||||
}
|
|
@ -9,18 +9,15 @@ import (
|
|||
)
|
||||
|
||||
func TestCrypt(t *testing.T) {
|
||||
key, err := keys.NewPrivateKey()
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
priv := privateKey{key}
|
||||
|
||||
pub := key.PublicKey()
|
||||
pub := priv.PublicKey()
|
||||
|
||||
data := []byte{1, 2, 3, 4}
|
||||
hash := sha256.Sum256(data)
|
||||
|
||||
sign, err := priv.Sign(data)
|
||||
require.NoError(t, err)
|
||||
sign := priv.Sign(data)
|
||||
require.True(t, pub.Verify(sign, hash[:]))
|
||||
|
||||
sign[0] = ^sign[0]
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/dbft"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
npayload "github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -119,9 +120,9 @@ func (p *Payload) EncodeBinary(w *io.BinWriter) {
|
|||
|
||||
// Sign signs payload using the private key.
|
||||
// It also sets corresponding verification and invocation scripts.
|
||||
func (p *Payload) Sign(key *privateKey) error {
|
||||
func (p *Payload) Sign(key *keys.PrivateKey) error {
|
||||
p.encodeData()
|
||||
sig := key.PrivateKey.SignHashable(uint32(p.network), &p.Extensible)
|
||||
sig := key.SignHashable(uint32(p.network), &p.Extensible)
|
||||
|
||||
buf := io.NewBufBinWriter()
|
||||
emit.Bytes(buf.BinWriter, sig)
|
||||
|
|
|
@ -249,11 +249,9 @@ func randomRecoveryMessage(t *testing.T) *recoveryMessage {
|
|||
}
|
||||
|
||||
func TestPayload_Sign(t *testing.T) {
|
||||
key, err := keys.NewPrivateKey()
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
priv := &privateKey{key}
|
||||
|
||||
p := randomPayload(t, prepareRequestType)
|
||||
h := priv.PublicKey().GetScriptHash()
|
||||
bc := newTestChain(t, false)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/nspcc-dev/dbft"
|
||||
"github.com/nspcc-dev/neo-go/internal/testchain"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -21,7 +22,7 @@ func TestRecoveryMessageSetters(t *testing.T) {
|
|||
|
||||
func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) {
|
||||
srv := newTestServiceWithState(t, enableStateRoot)
|
||||
privs := make([]*privateKey, testchain.Size())
|
||||
privs := make([]*keys.PrivateKey, testchain.Size())
|
||||
pubs := make([]dbft.PublicKey, testchain.Size())
|
||||
for i := range testchain.Size() {
|
||||
privs[i], pubs[i] = getTestValidator(i)
|
||||
|
|
Loading…
Reference in a new issue