Fix invalid staking transaction

pull/511/head
Rongjian Lan 6 years ago
parent a4858a0ea9
commit 537c6b289c
  1. 2
      api/service/discovery/service.go
  2. 27
      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 { 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 { } else {
utils.GetLogInstance().Info("[DISCOVERY]", "Sent Ping Message", g) utils.GetLogInstance().Info("[DISCOVERY]", "Sent Ping Message", g)
} }

@ -6,6 +6,8 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -143,19 +145,22 @@ func (s *Service) getFakeStakingInfo() *proto.StakingContractInfoResponse {
// Constructs the staking message // Constructs the staking message
func constructStakingMessage(ts types.Transactions) []byte { func constructStakingMessage(ts types.Transactions) []byte {
msg := &message.Message{ tsBytes, err := rlp.EncodeToBytes(ts)
Type: message.MessageType_NEWNODE_BEACON_STAKING, if err == nil {
Request: &message.Message_Staking{ msg := &message.Message{
Staking: &message.StakingRequest{ Type: message.MessageType_NEWNODE_BEACON_STAKING,
Transaction: ts.GetRlp(0), Request: &message.Message_Staking{
NodeId: "", Staking: &message.StakingRequest{
Transaction: tsBytes,
NodeId: "",
},
}, },
}, }
} if data, err := protobuf.Marshal(msg); err == nil {
if data, err := protobuf.Marshal(msg); err == nil { return data
return data }
} }
utils.GetLogInstance().Error("Error when creating staking message") utils.GetLogInstance().Error("Error when creating staking message", "error", err)
return nil 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 { if node.Role == BeaconLeader || node.Role == BeaconValidator {
node.CurrentStakes = make(map[common.Address]int64) 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.ConsensusBlock = make(chan *consensus.BFTBlockInfo)
node.Consensus.VerifiedNewBlock = make(chan *types.Block) node.Consensus.VerifiedNewBlock = make(chan *types.Block)
} }

@ -207,7 +207,8 @@ func (node *Node) addStakingTxnIntoPendingTxns(msgPayload []byte) {
if err == nil { if err == nil {
stakingRequest := msg.GetStaking() stakingRequest := msg.GetStaking()
txs := types.Transactions{} 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) node.addPendingTransactions(txs)
} else { } else {
utils.GetLogInstance().Error("Failed to unmarshal staking transaction list", "error", err) 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 // 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}) node.AddPeers([]*p2p.Peer{peer})
return 1 return 1

@ -47,7 +47,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}, stopChan chan
threshold = FirstTimeThreshold threshold = FirstTimeThreshold
firstTime = false 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 { if len(node.pendingTransactions) >= threshold {
// Normal tx block consensus // Normal tx block consensus
selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock) selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock)

Loading…
Cancel
Save