From 273db559a81e73eb4de2a8d24e2d4f6ddbfe7f70 Mon Sep 17 00:00:00 2001 From: iamsofonias Date: Wed, 5 Jul 2023 13:57:59 -0400 Subject: [PATCH] Revert BLS public key and signature in BlockProducerInfo (#567) --- lib/block_producer.go | 9 +- lib/blockchain.go | 17 ++- lib/blockchain_test.go | 13 ++- lib/constants.go | 16 --- lib/network.go | 231 +++++++---------------------------------- lib/network_test.go | 41 +------- lib/server.go | 3 +- 7 files changed, 59 insertions(+), 271 deletions(-) diff --git a/lib/block_producer.go b/lib/block_producer.go index 869531598..b4433124e 100644 --- a/lib/block_producer.go +++ b/lib/block_producer.go @@ -3,14 +3,13 @@ package lib import ( "encoding/hex" "fmt" + "github.com/btcsuite/btcd/wire" + "github.com/tyler-smith/go-bip39" "math" "sync" "sync/atomic" "time" - "github.com/btcsuite/btcd/wire" - "github.com/tyler-smith/go-bip39" - "github.com/deso-protocol/go-deadlock" "github.com/btcsuite/btcd/btcec" @@ -577,8 +576,8 @@ func (desoBlockProducer *DeSoBlockProducer) SignBlock(blockFound *MsgDeSoBlock) // If we get here, we now have a valid signature for the block. // Embed the signature into the block. - blockFound.BlockProducerInfo = &MsgDeSoBlockProducerInfo{ - PublicKey: NewPublicKey(desoBlockProducer.blockProducerPrivateKey.PubKey().SerializeCompressed()), + blockFound.BlockProducerInfo = &BlockProducerInfo{ + PublicKey: desoBlockProducer.blockProducerPrivateKey.PubKey().SerializeCompressed(), Signature: signature, } diff --git a/lib/blockchain.go b/lib/blockchain.go index 0e1ad5d63..59f38840e 100644 --- a/lib/blockchain.go +++ b/lib/blockchain.go @@ -5,6 +5,7 @@ import ( "container/list" "encoding/hex" "fmt" + "github.com/holiman/uint256" "math" "math/big" "reflect" @@ -13,8 +14,6 @@ import ( "strings" "time" - "github.com/holiman/uint256" - btcdchain "github.com/btcsuite/btcd/blockchain" chainlib "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/btcec" @@ -1831,35 +1830,35 @@ func (bc *Blockchain) ProcessBlock(desoBlock *MsgDeSoBlock, verifySignatures boo } // Verify that the public key is in the allowed set. - if _, exists := bc.trustedBlockProducerPublicKeys[MakePkMapKey(publicKey.ToBytes())]; !exists { + if _, exists := bc.trustedBlockProducerPublicKeys[MakePkMapKey(publicKey)]; !exists { return false, false, errors.Wrapf(RuleErrorBlockProducerPublicKeyNotInWhitelist, "ProcessBlock: Block producer public key %v is not in the allowed list of "+ - "--trusted_block_producer_public_keys: %v.", PkToStringBoth(publicKey.ToBytes()), + "--trusted_block_producer_public_keys: %v.", PkToStringBoth(publicKey), bc.trustedBlockProducerPublicKeys) } // Verify that the public key has not been forbidden. - dbEntry := DbGetForbiddenBlockSignaturePubKey(bc.db, bc.snapshot, publicKey.ToBytes()) + dbEntry := DbGetForbiddenBlockSignaturePubKey(bc.db, bc.snapshot, publicKey) if dbEntry != nil { return false, false, errors.Wrapf(RuleErrorForbiddenBlockProducerPublicKey, - "ProcessBlock: Block producer public key %v is forbidden", PkToStringBoth(publicKey.ToBytes())) + "ProcessBlock: Block producer public key %v is forbidden", PkToStringBoth(publicKey)) } // At this point we are confident that we have a valid public key that is // trusted. signature := desoBlock.BlockProducerInfo.Signature - pkObj, err := btcec.ParsePubKey(publicKey.ToBytes(), btcec.S256()) + pkObj, err := btcec.ParsePubKey(publicKey, btcec.S256()) if err != nil { return false, false, errors.Wrapf(err, "ProcessBlock: Error parsing block producer public key: %v.", - PkToStringBoth(publicKey.ToBytes())) + PkToStringBoth(publicKey)) } if !signature.Verify(blockHash[:], pkObj) { return false, false, errors.Wrapf(RuleErrorInvalidBlockProducerSIgnature, "ProcessBlock: Error validating signature %v for public key %v: %v.", hex.EncodeToString(signature.Serialize()), - PkToStringBoth(publicKey.ToBytes()), + PkToStringBoth(publicKey), err) } } diff --git a/lib/blockchain_test.go b/lib/blockchain_test.go index abce936db..11fa941a4 100644 --- a/lib/blockchain_test.go +++ b/lib/blockchain_test.go @@ -4,6 +4,8 @@ import ( "encoding/hex" "flag" "fmt" + embeddedpostgres "github.com/fergusstrange/embedded-postgres" + "github.com/go-pg/pg/v10" "log" "math/big" "math/rand" @@ -12,9 +14,6 @@ import ( "testing" "time" - embeddedpostgres "github.com/fergusstrange/embedded-postgres" - "github.com/go-pg/pg/v10" - chainlib "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcd/btcec" "github.com/dgraph-io/badger/v3" @@ -1652,12 +1651,12 @@ func TestBadBlockSignature(t *testing.T) { // Since MineAndProcesssSingleBlock returns a valid block above, we can play with its // signature and re-process the block to see what happens. - blockProducerInfoCopy := &MsgDeSoBlockProducerInfo{Signature: &btcec.Signature{}} - blockProducerInfoCopy.PublicKey = NewPublicKey(finalBlock1.BlockProducerInfo.PublicKey[:]) + blockProducerInfoCopy := &BlockProducerInfo{Signature: &btcec.Signature{}} + blockProducerInfoCopy.PublicKey = append([]byte{}, finalBlock1.BlockProducerInfo.PublicKey...) *blockProducerInfoCopy.Signature = *finalBlock1.BlockProducerInfo.Signature // A bad signature with the right public key should fail. - finalBlock1.BlockProducerInfo.PublicKey = NewPublicKey(senderPkBytes) + finalBlock1.BlockProducerInfo.PublicKey = senderPkBytes _, _, err = chain.ProcessBlock(finalBlock1, true) require.Error(err) require.Contains(err.Error(), RuleErrorInvalidBlockProducerSIgnature) @@ -1665,7 +1664,7 @@ func TestBadBlockSignature(t *testing.T) { // A signature that's outright missing should fail blockSignerPkBytes, _, err := Base58CheckDecode(blockSignerPk) require.NoError(err) - finalBlock1.BlockProducerInfo.PublicKey = NewPublicKey(blockSignerPkBytes) + finalBlock1.BlockProducerInfo.PublicKey = blockSignerPkBytes finalBlock1.BlockProducerInfo.Signature = nil _, _, err = chain.ProcessBlock(finalBlock1, true) require.Error(err) diff --git a/lib/constants.go b/lib/constants.go index 673856268..af7d892c5 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -141,22 +141,6 @@ const ( MsgValidatorTimeoutVersion0 MsgValidatorTimeoutVersion = 0 ) -// Versioning for the BlockProducerInfo field included in MsgDeSoBlock. This type alias -// is equivalent to a uint8, and supports the same byte encoders/decoders. -type MsgDeSoBlockProducerInfoVersion = byte - -const ( - // This represents the original schema for the BlockProducerInfo field included in - // Proof of Work blocks. The original schema did not have versioning, so we use a default - // version value of 0 to denote this. The original schema only contains the block producer's - // ECDSA public key and ECDSA signature of the block. - MsgDeSoBlockProducerInfoVersion0 MsgDeSoBlockProducerInfoVersion = 0 - // This version is introduced starting with Proof of Stake blocks. It adds versioning to the - // BlockProducerInfo schema, and adds two new fields for the block producer's BLS public key - // and BLS partial signature for the block. - MsgDeSoBlockProducerInfoVersion1 MsgDeSoBlockProducerInfoVersion = 1 -) - var ( MaxUint256, _ = uint256.FromHex("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") diff --git a/lib/network.go b/lib/network.go index e45ce7704..07091a1f9 100644 --- a/lib/network.go +++ b/lib/network.go @@ -23,7 +23,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/davecgh/go-spew/spew" decredEC "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa" - "github.com/deso-protocol/core/bls" merkletree "github.com/deso-protocol/go-merkle-tree" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/holiman/uint256" @@ -2367,112 +2366,15 @@ func (msg *MsgDeSoHeader) String() string { // BLOCK Message // ================================================================== -type MsgDeSoBlockProducerInfo struct { - Version MsgDeSoBlockProducerInfoVersion - - // ECDSA public key for the block producer. - PublicKey *PublicKey - // The block producer's ECDSA signature for the block. This field is used in - // MsgDeSoBlockProducerInfo version 0, and is deprecated from version 1 onwards. +type BlockProducerInfo struct { + PublicKey []byte Signature *btcec.Signature - - // The BLS public key of the validator who constructed this block. This field is - // populated starting in MsgDeSoBlockProducerInfo version 1. - VotingPublicKey *bls.PublicKey - // The validator's partial BLS signature of the (ProposedInView, BlockHash) pair - // for enclosing block. This signature proves the validator proposed the block, - // and also acts as the validator's vote for this block. This filed is only populated - // starting in MsgDeSoBlockProducerInfo version 1. - VotePartialSignature *bls.Signature -} - -// Byte encoder for the MsgDeSoBlockProducerInfo with support for versioning. The encoder only -// supports MsgDeSoBlockProducerInfo version 1 and above. For the legacy version 0, use the -// MsgDeSoBlockProducerInfo.Serialize_Legacy() method instead. -func (bpi *MsgDeSoBlockProducerInfo) ToBytes() ([]byte, error) { - // Only support byte encoding for BlockProducerInfo version 1. All later versions will - // need differ in format, so their encoding can be implemented then. - if bpi.Version != MsgDeSoBlockProducerInfoVersion1 { - return nil, fmt.Errorf("MsgDeSoBlockProducerInfo.ToBytes: BlockProducerInfo version %d not supported", bpi.Version) - } - - encodedBytes := []byte{} - - // Required Version field - encodedBytes = append(encodedBytes, bpi.Version) - - // Required ECDSA PublicKey - if bpi.PublicKey == nil { - return nil, fmt.Errorf("MsgDeSoBlockProducerInfo.ToBytes: PublicKey is required") - } - encodedBytes = append(encodedBytes, bpi.PublicKey.ToBytes()...) - - // The ECDSA Signature is redundant, and is removed in MsgDeSoBlockProducerInfo version 1 and above - - // Voting BLS PublicKey - if bpi.VotingPublicKey == nil { - return nil, fmt.Errorf("MsgDeSoBlockProducerInfo.ToBytes: VotingPublicKey is required") - } - encodedBytes = append(encodedBytes, EncodeByteArray(bpi.VotingPublicKey.ToBytes())...) - - // Vote BLS Partial Signature - if bpi.VotePartialSignature == nil { - return nil, fmt.Errorf("MsgDeSoBlockProducerInfo.ToBytes: VotePartialSignature is required") - } - encodedBytes = append(encodedBytes, EncodeByteArray(bpi.VotePartialSignature.ToBytes())...) - - return encodedBytes, nil -} - -// Byte decoder for the MsgDeSoBlockProducerInfo with support for versioning. The decoder only -// supports MsgDeSoBlockProducerInfo version 1 and above. For the legacy version 0, use the -// MsgDeSoBlockProducerInfo.Deserialize_Legacy() method instead. -func (bpi *MsgDeSoBlockProducerInfo) FromBytes(rr *bytes.Reader) error { - var err error - - // Required Version field - bpi.Version, err = rr.ReadByte() - if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.FromBytes: Problem reading Version") - } - - // Only support byte decoding for BlockProducerInfo version 1. All later versions will - // need differ in format, so their decoding can be implemented then. - if bpi.Version != MsgDeSoBlockProducerInfoVersion1 { - return fmt.Errorf("MsgDeSoBlockProducerInfo.FromBytes: BlockProducerInfo version %d not supported", bpi.Version) - } - - // Required ECDSA PublicKey - bpi.PublicKey, err = ReadPublicKey(rr) - if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.FromBytes: Problem reading PublicKey") - } - - // The ECDSA Signature is redundant, and is removed in MsgDeSoBlockProducerInfo version 1 and above - // so we skip it here. - - // Voting BLS PublicKey - bpi.VotingPublicKey, err = DecodeBLSPublicKey(rr) - if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.FromBytes: Problem reading VotingPublicKey") - } - - // Vote BLS Partial Signature - bpi.VotePartialSignature, err = DecodeBLSSignature(rr) - if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.FromBytes: Problem reading VotePartialSignature") - } - - return nil } -// Legacy byte encoder for MsgDeSoBlockProducerInfo with no support for versioning. -// It encodes just the public key and signature according to the legacy encoding -// format. -func (bpi *MsgDeSoBlockProducerInfo) Serialize_Legacy() []byte { +func (bpi *BlockProducerInfo) Serialize() []byte { data := []byte{} data = append(data, UintToBuf(uint64(len(bpi.PublicKey)))...) - data = append(data, bpi.PublicKey.ToBytes()...) + data = append(data, bpi.PublicKey...) sigBytes := []byte{} if bpi.Signature != nil { @@ -2484,47 +2386,46 @@ func (bpi *MsgDeSoBlockProducerInfo) Serialize_Legacy() []byte { return data } -// Legacy byte decoder for MsgDeSoBlockProducerInfo with no support for versioning. -// It decodes the public key and signature according to the legacy encoding -// format and then sets the version to 0. -func (bpi *MsgDeSoBlockProducerInfo) Deserialize_Legacy(data []byte) error { - ret := &MsgDeSoBlockProducerInfo{} +func (bpi *BlockProducerInfo) Deserialize(data []byte) error { + ret := &BlockProducerInfo{} rr := bytes.NewReader(data) - // Set the version to 0 since this is the legacy format. - ret.Version = MsgDeSoBlockProducerInfoVersion0 - // De-serialize the public key. { pkLen, err := ReadUvarint(rr) if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: Error reading public key len") + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Error reading public key len") } if pkLen > MaxMessagePayload { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: pkLen too long: %v", pkLen) + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: pkLen too long: %v", pkLen) } - ret.PublicKey, err = ReadPublicKey(rr) + pkBytes, err := SafeMakeSliceWithLength[byte](pkLen) if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: Error reading public key: ") + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Problem making slice for pkBytes") } + _, err = io.ReadFull(rr, pkBytes) + if err != nil { + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Error reading public key: ") + } + ret.PublicKey = pkBytes } // De-serialize the signature. { sigLen, err := ReadUvarint(rr) if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: Error reading signature len") + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Error reading signature len") } if sigLen > MaxMessagePayload { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: signature len too long: %v", sigLen) + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: signature len too long: %v", sigLen) } sigBytes, err := SafeMakeSliceWithLength[byte](sigLen) if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: Problem making slice for sigBytes") + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Problem making slice for sigBytes") } _, err = io.ReadFull(rr, sigBytes) if err != nil { - return errors.Wrapf(err, "MsgDeSoBlockProducerInfo.Deserialize: Error reading signature: ") + return errors.Wrapf(err, "BlockProducerInfo.Deserialize: Error reading signature: ") } ret.Signature = nil if sigLen > 0 { @@ -2540,32 +2441,22 @@ func (bpi *MsgDeSoBlockProducerInfo) Deserialize_Legacy(data []byte) error { return nil } -func (bpi *MsgDeSoBlockProducerInfo) String() string { +func (bpi *BlockProducerInfo) String() string { if bpi == nil || len(bpi.PublicKey) == 0 { return "Signer Key: NONE" } - return fmt.Sprintf("Signer Key: %v", PkToStringMainnet(bpi.PublicKey.ToBytes())) + return fmt.Sprintf("Signer Key: %v", PkToStringMainnet(bpi.PublicKey)) } type MsgDeSoBlock struct { Header *MsgDeSoHeader Txns []*MsgDeSoTxn - // This field describes the producer of the block and their signature for the block. - // - // In Proof of Work blocks, the field is optional and provides the producer of the block - // the ability to sign the block with its ECDSA private key. Doing this proves that this block - // was produced by a particular entity, which can be useful for nodes that want to restrict - // who they accept blocks from. - // - // In Proof of Stake blocks, this field is required and serves two purposes: - // 1. It allows the block producer to sign the block with its BLS private key. - // This allows validators to verify that the block was produced by the expected leader for the - // current block height and view. - // 2. It contains the block producer's BLS partial signature, which acts as their vote on the - // block. This way, the vote can be aggregated into a QC by the next block proposer in the leader - // schedule. - BlockProducerInfo *MsgDeSoBlockProducerInfo + // This field is optional and provides the producer of the block the ability to sign it + // with their private key. Doing this proves that this block was produced by a particular + // entity, which can be useful for nodes that want to restrict who they accept blocks + // from. + BlockProducerInfo *BlockProducerInfo } func (msg *MsgDeSoBlock) EncodeBlockCommmon(preSignature bool) ([]byte, error) { @@ -2610,7 +2501,7 @@ func (msg *MsgDeSoBlock) EncodeBlockVersion1(preSignature bool) ([]byte, error) // BlockProducerInfo blockProducerInfoBytes := []byte{} if msg.BlockProducerInfo != nil { - blockProducerInfoBytes = msg.BlockProducerInfo.Serialize_Legacy() + blockProducerInfoBytes = msg.BlockProducerInfo.Serialize() } data = append(data, UintToBuf(uint64(len(blockProducerInfoBytes)))...) data = append(data, blockProducerInfoBytes...) @@ -2618,33 +2509,11 @@ func (msg *MsgDeSoBlock) EncodeBlockVersion1(preSignature bool) ([]byte, error) return data, nil } -func (msg *MsgDeSoBlock) EncodeBlockVersion2(preSignature bool) ([]byte, error) { - // Encode MsgDeSoHeader and []*MsgDeSoTxn - encodedBytes, err := msg.EncodeBlockCommmon(preSignature) - if err != nil { - return nil, err - } - - // Encode BlockProducerInfo - if msg.BlockProducerInfo == nil { - return nil, fmt.Errorf("MsgDeSoBlock.EncodeBlockVersion2: BlockProducerInfo should not be nil") - } - blockProducerInfoBytes, err := msg.BlockProducerInfo.ToBytes() - if err != nil { - return nil, errors.Wrapf(err, "MsgDeSoBlock.EncodeBlockVersion2: Problem encoding BlockProducerInfo") - } - encodedBytes = append(encodedBytes, EncodeByteArray(blockProducerInfoBytes)...) - - return encodedBytes, nil -} - func (msg *MsgDeSoBlock) ToBytes(preSignature bool) ([]byte, error) { if msg.Header.Version == HeaderVersion0 { return msg.EncodeBlockVersion0(preSignature) } else if msg.Header.Version == HeaderVersion1 { return msg.EncodeBlockVersion1(preSignature) - } else if msg.Header.Version == HeaderVersion2 { - return msg.EncodeBlockVersion2(preSignature) } else { return nil, fmt.Errorf("MsgDeSoBlock.ToBytes: Error encoding version: %v", msg.Header.Version) } @@ -2707,21 +2576,15 @@ func (msg *MsgDeSoBlock) FromBytes(data []byte) error { ret.Txns = append(ret.Txns, currentTxn) } - // Version 0 blocks have no BlockProducerInfo attached to them. We can exit early here. - if ret.Header.Version == HeaderVersion0 { - *msg = *ret - return nil - } - - // Starting with version 1, all block versions have a BlockProducerInfo length encoded. - blockProducerInfoLen, err := ReadUvarint(rr) - if err != nil { - return errors.Wrapf(err, "MsgDeSoBlock.FromBytes: Error decoding header length") - } - + // Version 1 blocks have a BlockProducerInfo attached to them that + // must be read. If this is not a Version 1 block, then the BlockProducerInfo + // remains nil. if ret.Header.Version == HeaderVersion1 { - // All version 1 blocks have an optional BlockProducerInfo attached. - var blockProducerInfo *MsgDeSoBlockProducerInfo + blockProducerInfoLen, err := ReadUvarint(rr) + if err != nil { + return errors.Wrapf(err, "MsgDeSoBlock.FromBytes: Error decoding header length") + } + var blockProducerInfo *BlockProducerInfo if blockProducerInfoLen > 0 { if blockProducerInfoLen > MaxMessagePayload { return fmt.Errorf("MsgDeSoBlock.FromBytes: Header length %d longer "+ @@ -2735,32 +2598,12 @@ func (msg *MsgDeSoBlock) FromBytes(data []byte) error { if err != nil { return errors.Wrapf(err, "MsgDeSoBlock.FromBytes: Problem reading header") } - blockProducerInfo = &MsgDeSoBlockProducerInfo{} - if err = blockProducerInfo.Deserialize_Legacy(blockProducerInfoBytes); err != nil { + blockProducerInfo = &BlockProducerInfo{} + if err = blockProducerInfo.Deserialize(blockProducerInfoBytes); err != nil { return errors.Wrapf(err, "MsgDeSoBlock.FromBytes: Error deserializing block producer info") } ret.BlockProducerInfo = blockProducerInfo } - } else if ret.Header.Version == HeaderVersion2 { - // All version 2 blocks have a required BlockProducerInfo field. - - // Verify the length for the BlockProducerInfo. - if blockProducerInfoLen > MaxMessagePayload { - return fmt.Errorf("MsgDeSoBlock.FromBytes: BlockProducerInfo length %d longer "+ - "than max %d", blockProducerInfoLen, MaxMessagePayload) - } - - // BlockProducerInfo is a required field for block header version 2 and later. Otherwise, - // the block is considered malformed. - if blockProducerInfoLen == 0 { - return fmt.Errorf("MsgDeSoBlock.FromBytes: BlockProducerInfo length cannot be zero") - } - - blockProducerInfo := &MsgDeSoBlockProducerInfo{} - if blockProducerInfo.FromBytes(rr); err != nil { - return errors.Wrapf(err, "MsgDeSoBlock.FromBytes: Error decoding BlockProducerInfo") - } - ret.BlockProducerInfo = blockProducerInfo } *msg = *ret diff --git a/lib/network_test.go b/lib/network_test.go index 86728e3be..0afb5322a 100644 --- a/lib/network_test.go +++ b/lib/network_test.go @@ -163,17 +163,6 @@ func createTestBlockHeaderVersion2(t *testing.T) *MsgDeSoHeader { } } -func createTestBlockProducerInfoVersion1(t *testing.T) *MsgDeSoBlockProducerInfo { - testBLSPublicKey, testBLSSignature := _generateValidatorVotingPublicKeyAndSignature(t) - - return &MsgDeSoBlockProducerInfo{ - Version: 1, - PublicKey: NewPublicKey(pkForTesting1), - VotingPublicKey: testBLSPublicKey, - VotePartialSignature: testBLSSignature, - } -} - func TestHeaderConversionAndReadWriteMessage(t *testing.T) { assert := assert.New(t) require := require.New(t) @@ -339,14 +328,14 @@ var expectedBlock = &MsgDeSoBlock{ Header: expectedBlockHeaderVersion1, Txns: expectedTransactions(true), // originally was effectively false - BlockProducerInfo: &MsgDeSoBlockProducerInfo{ - PublicKey: NewPublicKey([]byte{ + BlockProducerInfo: &BlockProducerInfo{ + PublicKey: []byte{ // random bytes 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x10, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x21, 0x22, 0x23, - }), + }, }, } @@ -498,30 +487,6 @@ var expectedV0Header = &MsgDeSoHeader{ Nonce: uint64(123456), } -func TestSerializeBlockVersion2(t *testing.T) { - assert := assert.New(t) - require := require.New(t) - _ = assert - _ = require - - originalBlock := &MsgDeSoBlock{ - Header: createTestBlockHeaderVersion2(t), - BlockProducerInfo: createTestBlockProducerInfoVersion1(t), - } - - encodedBytes, err := originalBlock.ToBytes(false) - require.NoError(err) - - decodedBlock := NewMessage(MsgTypeBlock).(*MsgDeSoBlock) - err = decodedBlock.FromBytes(encodedBytes) - require.NoError(err) - - assert.Equal(originalBlock.Header.Version, decodedBlock.Header.Version) - assert.Equal(originalBlock.BlockProducerInfo.PublicKey, decodedBlock.BlockProducerInfo.PublicKey) - assert.True(originalBlock.BlockProducerInfo.VotingPublicKey.Eq(decodedBlock.BlockProducerInfo.VotingPublicKey)) - assert.True(originalBlock.BlockProducerInfo.VotePartialSignature.Eq(decodedBlock.BlockProducerInfo.VotePartialSignature)) -} - func TestBlockSerialize(t *testing.T) { assert := assert.New(t) require := require.New(t) diff --git a/lib/server.go b/lib/server.go index a6974953f..18e9ade70 100644 --- a/lib/server.go +++ b/lib/server.go @@ -1795,8 +1795,7 @@ func (srv *Server) _handleBlock(pp *Peer, blk *MsgDeSoBlock) { if len(srv.blockchain.trustedBlockProducerPublicKeys) > 0 && blockHeader.Height >= srv.blockchain.trustedBlockProducerStartHeight { if blk.BlockProducerInfo != nil { _, entryExists := srv.mempool.readOnlyUtxoView.ForbiddenPubKeyToForbiddenPubKeyEntry[MakePkMapKey( - blk.BlockProducerInfo.PublicKey.ToBytes(), - )] + blk.BlockProducerInfo.PublicKey)] if entryExists { srv._logAndDisconnectPeer(pp, blk, "Got forbidden block signature public key.") return