polish code by gofmt

pull/8/head
Minh Doan 7 years ago
parent 57876da839
commit 2a05aedbf5
  1. 6
      blockchain/block.go
  2. 4
      blockchain/blockchain.go
  3. 2
      blockchain/utxopool.go
  4. 2
      common/message.go
  5. 5
      consensus/consensus_leader.go
  6. 11
      consensus/consensus_validator.go
  7. 2
      node/message.go
  8. 2
      node/node_test.go

@ -17,9 +17,7 @@ type Block struct {
Hash [32]byte Hash [32]byte
NumTransactions int32 NumTransactions int32
TransactionIds [][32]byte TransactionIds [][32]byte
Transactions []*Transaction // Transactions
// Transactions
Transactions []*Transaction
// Signature... // Signature...
} }
@ -77,7 +75,7 @@ func NewBlock(transactions []*Transaction, prevBlockHash [32]byte) *Block {
for _, tx := range transactions { for _, tx := range transactions {
txIds = append(txIds, tx.ID) txIds = append(txIds, tx.ID)
} }
block := &Block{time.Now().Unix(), prevBlockHash, [32]byte{},numTxs, txIds,transactions} block := &Block{time.Now().Unix(), prevBlockHash, [32]byte{}, numTxs, txIds, transactions}
copy(block.Hash[:], block.HashTransactions()[:]) // TODO(Minh): the blockhash should be a hash of everything in the block copy(block.Hash[:], block.HashTransactions()[:]) // TODO(Minh): the blockhash should be a hash of everything in the block
return block return block

@ -13,11 +13,11 @@ type Blockchain struct {
const genesisCoinbaseData = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" const genesisCoinbaseData = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
// Get the latest block at the end of the chain // Get the latest block at the end of the chain
func (bc *Blockchain) GetLatestBlock() *Block{ func (bc *Blockchain) GetLatestBlock() *Block {
if len(bc.Blocks) == 0 { if len(bc.Blocks) == 0 {
return nil return nil
} }
return bc.Blocks[len(bc.Blocks) - 1] return bc.Blocks[len(bc.Blocks)-1]
} }
// FindUnspentTransactions returns a list of transactions containing unspent outputs // FindUnspentTransactions returns a list of transactions containing unspent outputs

@ -26,7 +26,7 @@ type UTXOPool struct {
outputIndex2 - value2 outputIndex2 - value2
] ]
] ]
*/ */
UtxoMap map[string]map[string]map[int]int UtxoMap map[string]map[string]map[int]int
} }

@ -35,7 +35,6 @@ const (
// TODO: add more types // TODO: add more types
) )
// The specific types of message under COMMITTEE category // The specific types of message under COMMITTEE category
type CommitteeMessageType byte type CommitteeMessageType byte
@ -53,7 +52,6 @@ const (
// TODO: add more types // TODO: add more types
) )
// Get the message category from the p2p message content // Get the message category from the p2p message content
func GetMessageCategory(message []byte) (MessageCategory, error) { func GetMessageCategory(message []byte) (MessageCategory, error) {
if len(message) < NODE_TYPE_BYTES { if len(message) < NODE_TYPE_BYTES {

@ -4,11 +4,11 @@ import (
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"encoding/binary" "encoding/binary"
"encoding/gob"
"fmt"
"harmony-benchmark/blockchain" "harmony-benchmark/blockchain"
"harmony-benchmark/p2p" "harmony-benchmark/p2p"
"strings" "strings"
"encoding/gob"
"fmt"
"time" "time"
) )
@ -276,7 +276,6 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
_ = response _ = response
_ = signature _ = signature
// check consensus Id // check consensus Id
if consensusId != consensus.consensusId { if consensusId != consensus.consensusId {
consensus.Log.Debug("[ERROR] Received RESPONSE with wrong consensus Id", "myConsensusId", consensus.consensusId, "theirConsensusId", consensusId, "consensus", consensus) consensus.Log.Debug("[ERROR] Received RESPONSE with wrong consensus Id", "myConsensusId", consensus.consensusId, "theirConsensusId", consensusId, "consensus", consensus)

@ -3,12 +3,12 @@ package consensus
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"harmony-benchmark/p2p"
"strconv"
"regexp"
"encoding/gob" "encoding/gob"
"harmony-benchmark/blockchain"
"fmt" "fmt"
"harmony-benchmark/blockchain"
"harmony-benchmark/p2p"
"regexp"
"strconv"
) )
// Validator's consensus message dispatcher // Validator's consensus message dispatcher
@ -226,7 +226,6 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
return return
} }
// TODO: verify aggregated commits with real schnor cosign verification // TODO: verify aggregated commits with real schnor cosign verification
// TODO: return the signature(response) to leader // TODO: return the signature(response) to leader
@ -253,7 +252,6 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
consensus.consensusId++ // roll up one by one, until the next block is not received yet. consensus.consensusId++ // roll up one by one, until the next block is not received yet.
consensus.mutex.Unlock() consensus.mutex.Unlock()
// TODO: think about when validators know about the consensus is reached. // TODO: think about when validators know about the consensus is reached.
// For now, the blockchain is updated right here. // For now, the blockchain is updated right here.
@ -277,7 +275,6 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
} }
} }
// Construct the response message to send to leader (assumption the consensus data is already verified) // Construct the response message to send to leader (assumption the consensus data is already verified)

@ -9,6 +9,7 @@ import (
// The types of messages used for NODE/TRANSACTION // The types of messages used for NODE/TRANSACTION
type TransactionMessageType int type TransactionMessageType int
const ( const (
SEND TransactionMessageType = iota SEND TransactionMessageType = iota
REQUEST REQUEST
@ -16,6 +17,7 @@ const (
// The types of messages used for NODE/CONTROL // The types of messages used for NODE/CONTROL
type ControlMessageType int type ControlMessageType int
const ( const (
STOP ControlMessageType = iota STOP ControlMessageType = iota
) )

@ -1,9 +1,9 @@
package node package node
import ( import (
"harmony-benchmark/consensus"
"harmony-benchmark/p2p" "harmony-benchmark/p2p"
"testing" "testing"
"harmony-benchmark/consensus"
) )
func TestNewNewNode(test *testing.T) { func TestNewNewNode(test *testing.T) {

Loading…
Cancel
Save