diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-11 15:00:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-11 15:00:48 +0800 |
commit | a13f15bf54a2c10e5223779877778da0eebb4855 (patch) | |
tree | d9c2e60d0f42a5aa37d423e6ca81a9ba2af8645b /core | |
parent | 360a88aee800d25a942aeb8917e9b6ef0690aa27 (diff) | |
download | dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar.gz dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar.bz2 dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar.lz dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar.xz dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.tar.zst dexon-consensus-a13f15bf54a2c10e5223779877778da0eebb4855.zip |
core: types: fix nodeID generation (#191)
Use ethereum style nodeID generation (keccak on compressed public key
without the first byte).
Diffstat (limited to 'core')
-rw-r--r-- | core/authenticator.go | 2 | ||||
-rw-r--r-- | core/lattice.go | 2 | ||||
-rw-r--r-- | core/test/tcp-transport.go | 6 | ||||
-rw-r--r-- | core/types/node.go | 6 |
4 files changed, 10 insertions, 6 deletions
diff --git a/core/authenticator.go b/core/authenticator.go index 97b62d6..5415f96 100644 --- a/core/authenticator.go +++ b/core/authenticator.go @@ -123,7 +123,7 @@ func (au *Authenticator) VerifyBlock(b *types.Block) (err error) { if err != nil { return } - if !b.ProposerID.Equal(crypto.Keccak256Hash(pubKey.Bytes())) { + if !b.ProposerID.Equal(types.NewNodeID(pubKey)) { err = ErrIncorrectSignature return } diff --git a/core/lattice.go b/core/lattice.go index ca9d839..3ee0b94 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -109,7 +109,7 @@ func (s *Lattice) SanityCheck(b *types.Block) (err error) { if err != nil { return } - if !b.ProposerID.Equal(crypto.Keccak256Hash(pubKey.Bytes())) { + if !b.ProposerID.Equal(types.NewNodeID(pubKey)) { err = ErrIncorrectSignature return } diff --git a/core/test/tcp-transport.go b/core/test/tcp-transport.go index e1b73f0..64f915d 100644 --- a/core/test/tcp-transport.go +++ b/core/test/tcp-transport.go @@ -709,12 +709,16 @@ func NewTCPTransportServer( marshaller Marshaller, serverPort int) *TCPTransportServer { + prvKey, err := ecdsa.NewPrivateKey() + if err != nil { + panic(err) + } return &TCPTransportServer{ // NOTE: the assumption here is the node ID of peers // won't be zero. TCPTransport: *NewTCPTransport( TransportPeerServer, - ecdsa.NewPublicKeyFromByteSlice(nil), + prvKey.PublicKey(), nil, marshaller, serverPort), diff --git a/core/types/node.go b/core/types/node.go index 177e407..839c2bf 100644 --- a/core/types/node.go +++ b/core/types/node.go @@ -32,12 +32,12 @@ type NodeID struct { // NewNodeID returns a NodeID with Hash set to the hash value of // public key. func NewNodeID(pubKey crypto.PublicKey) NodeID { - return NodeID{Hash: crypto.Keccak256Hash(pubKey.Bytes())} + return NodeID{Hash: crypto.Keccak256Hash(pubKey.Bytes()[1:])} } // Equal checks if the hash representation is the same NodeID. -func (v NodeID) Equal(hash common.Hash) bool { - return v.Hash == hash +func (v NodeID) Equal(v2 NodeID) bool { + return v.Hash == v2.Hash } // NodeIDs implements sort.Interface for NodeID. |