Fix invalid staking transaction

pull/511/head
Rongjian Lan 6 years ago
parent a4858a0ea9
commit 537c6b289c
  1. 2
      api/service/discovery/service.go
  2. 9
      api/service/staking/service.go
  3. 2
      node/node.go
  4. 4
      node/node_handler.go
  5. 2
      node/node_newblock.go

@ -129,7 +129,7 @@ func (s *Service) contactP2pPeers() {
}
}
if err != nil {
utils.GetLogInstance().Error("Failed to send ping message", "group", g)
utils.GetLogInstance().Error("[DISCOVERY] Failed to send ping message", "group", g)
} else {
utils.GetLogInstance().Info("[DISCOVERY]", "Sent Ping Message", g)
}

@ -6,6 +6,8 @@ import (
"math/big"
"time"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
@ -143,11 +145,13 @@ func (s *Service) getFakeStakingInfo() *proto.StakingContractInfoResponse {
// Constructs the staking message
func constructStakingMessage(ts types.Transactions) []byte {
tsBytes, err := rlp.EncodeToBytes(ts)
if err == nil {
msg := &message.Message{
Type: message.MessageType_NEWNODE_BEACON_STAKING,
Request: &message.Message_Staking{
Staking: &message.StakingRequest{
Transaction: ts.GetRlp(0),
Transaction: tsBytes,
NodeId: "",
},
},
@ -155,7 +159,8 @@ func constructStakingMessage(ts types.Transactions) []byte {
if data, err := protobuf.Marshal(msg); err == nil {
return data
}
utils.GetLogInstance().Error("Error when creating staking message")
}
utils.GetLogInstance().Error("Error when creating staking message", "error", err)
return nil
}

@ -260,7 +260,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database) *N
if node.Role == BeaconLeader || node.Role == BeaconValidator {
node.CurrentStakes = make(map[common.Address]int64)
}
utils.GetLogInstance().Debug("Received", "blockHash", chain.GetBlockByNumber(0).Hash().Hex())
utils.GetLogInstance().Debug("Created Genesis Block", "blockHash", chain.GetBlockByNumber(0).Hash().Hex())
node.Consensus.ConsensusBlock = make(chan *consensus.BFTBlockInfo)
node.Consensus.VerifiedNewBlock = make(chan *types.Block)
}

@ -207,7 +207,8 @@ func (node *Node) addStakingTxnIntoPendingTxns(msgPayload []byte) {
if err == nil {
stakingRequest := msg.GetStaking()
txs := types.Transactions{}
if err = rlp.DecodeBytes(stakingRequest.Transaction, txs); err == nil {
if err = rlp.DecodeBytes(stakingRequest.Transaction, &txs); err == nil {
utils.GetLogInstance().Error("Successfully added staking transaction to pending list.")
node.addPendingTransactions(txs)
} else {
utils.GetLogInstance().Error("Failed to unmarshal staking transaction list", "error", err)
@ -357,6 +358,7 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender string) int {
}
// Add to Node's peer list anyway
utils.GetLogInstance().Info("Add Peer to Node", "Node", node.Consensus.GetNodeID(), "Pear", peer)
node.AddPeers([]*p2p.Peer{peer})
return 1

@ -47,7 +47,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}, stopChan chan
threshold = FirstTimeThreshold
firstTime = false
}
utils.GetLogInstance().Debug("STARTING BLOCK", "threshold", threshold, "pendingTransactions", len(node.pendingTransactions))
utils.GetLogInstance().Debug("Proposing New Block...", "threshold", threshold, "pendingTransactions", len(node.pendingTransactions))
if len(node.pendingTransactions) >= threshold {
// Normal tx block consensus
selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock)

Loading…
Cancel
Save