Minh Doan 6 years ago
parent 29b3281d4a
commit 0e34dcf448
  1. 2
      blockchain/blockchain.go
  2. 5
      blockchain/utxopool.go
  3. 4
      client/btctxgen/main.go
  4. 2
      client/config/config.go
  5. 4
      client/txgen/main.go
  6. 4
      client/wallet/main.go
  7. 4
      consensus/consensus.go
  8. 6
      consensus/consensus_validator.go
  9. 1
      node/node.go
  10. 2
      p2p/peer.go
  11. 5
      pow/api.go
  12. 6
      proto/consensus/consensus.go
  13. 3
      syncing/syncing.go
  14. 2
      utils/distribution_config.go

@ -21,7 +21,7 @@ func (bc *Blockchain) FindBlock(blockHash []byte) *Block {
return nil
}
for _, block := range bc.Blocks {
if bytes.Compare(block.Hash[:], blockHash[:]) == 0 {
if bytes.Equal(block.Hash[:], blockHash[:]) {
return block
}
}

@ -472,10 +472,7 @@ func (utxoPool *UTXOPool) LockedUtxoExists(address [20]byte, txID string, index
return false
}
_, ok = utxoPool.LockedUtxoMap[address][txID][index]
if !ok {
return false
}
return true
return ok
}
// DeleteOneLockedUtxo deletes one balance item of UTXOPool and clean up if possible.

@ -104,7 +104,7 @@ func generateSimulatedTransactions(shardID int, dataNodes []*node.Node) ([]*bloc
cnt := 0
LOOP:
for true {
for {
btcTx := iter.NextTx()
if btcTx == nil {
log.Error("Failed to parse tx", "height", iter.GetBlockIndex())
@ -255,7 +255,7 @@ func main() {
leaders = append(leaders, leader)
}
for true {
for {
allCrossTxs := []*blockchain.Transaction{}
// Generate simulated transactions
for shardID, leader := range shardIDLeaderMap {

@ -83,11 +83,11 @@ func (config *Config) GetClientPort() string {
// ReadConfigFile parses the config file and return a 2d array containing the file data
func (config *Config) ReadConfigFile(filename string) error {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
log.Fatal("Failed to read config file ", filename)
return err
}
defer file.Close()
fscanner := bufio.NewScanner(file)
result := []Entry{}

@ -148,7 +148,7 @@ func generateCrossShardTx(txInfo *TxInfo) {
nodeShardID := txInfo.dataNodes[txInfo.shardID].Consensus.ShardID
crossShardID := nodeShardID
// a random shard to spend money to
for true {
for {
crossShardID = uint32(rand.Intn(len(txInfo.dataNodes)))
if crossShardID != nodeShardID {
break
@ -335,7 +335,7 @@ func main() {
client.InitLookUpIntPriKeyMap()
subsetCounter := 0
for true {
for {
t := time.Now()
if totalTime > 0 && t.Sub(start).Seconds() >= totalTime {
log.Debug("Generator timer ended.", "duration", (int(t.Sub(start))), "startTime", start, "totalTime", totalTime)

@ -275,7 +275,7 @@ func ExecuteTransaction(tx blockchain.Transaction, walletNode *node.Node) error
doneSignal := make(chan int)
go func() {
for true {
for {
if len(walletNode.Client.PendingCrossTxs) == 0 {
doneSignal <- 0
break
@ -300,7 +300,7 @@ func FetchUtxos(addresses [][20]byte, walletNode *node.Node) (map[uint32]blockch
doneSignal := make(chan int)
go func() {
for true {
for {
if len(walletNode.Client.ShardUtxoMap) == len(*walletNode.Client.Leaders) {
doneSignal <- 0
break

@ -87,8 +87,8 @@ type Consensus struct {
// should be stored in this temporary structure. In case the round N-1 finishes, it can catch
// up to the latest state of round N by using this structure.
type BlockConsensusStatus struct {
blockHeader []byte // the block header of the block which the consensus is running on
state State // the latest state of the consensus
blockHeader []byte // the block header of the block which the consensus is running on
state State // the latest state of the consensus
}
// NewConsensus creates a new Consensus object

@ -111,7 +111,7 @@ func (consensus *Consensus) processAnnounceMessage(payload []byte) {
}
// check block hash
if bytes.Compare(blockHash[:], blockHeaderObj.CalculateBlockHash()[:]) != 0 || bytes.Compare(blockHeaderObj.Hash[:], blockHeaderObj.CalculateBlockHash()[:]) != 0 {
if !bytes.Equal(blockHash[:], blockHeaderObj.CalculateBlockHash()[:]) || !bytes.Equal(blockHeaderObj.Hash[:], blockHeaderObj.CalculateBlockHash()[:]) {
consensus.Log.Warn("Block hash doesn't match", "consensus", consensus)
return
}
@ -193,7 +193,7 @@ func (consensus *Consensus) processChallengeMessage(payload []byte, targetState
defer consensus.mutex.Unlock()
// check block hash
if bytes.Compare(blockHash[:], consensus.blockHash[:]) != 0 {
if !bytes.Equal(blockHash[:], consensus.blockHash[:]) {
consensus.Log.Warn("Block hash doesn't match", "consensus", consensus)
return
}
@ -353,7 +353,7 @@ func (consensus *Consensus) processCollectiveSigMessage(payload []byte) {
}
// check block hash
if bytes.Compare(blockHash[:], consensus.blockHash[:]) != 0 {
if !bytes.Equal(blockHash[:], consensus.blockHash[:]) {
consensus.Log.Warn("Block hash doesn't match", "consensus", consensus)
return
}

@ -127,7 +127,6 @@ func (node *Node) countNumTransactionsInBlockchain() int {
func (node *Node) ConnectIdentityChain() {
IDCPeer := node.IDCPeer
p2p.SendMessage(IDCPeer, identity.ConstructIdentityMessage(identity.Announce, node.SerializeWaitNode()))
return
}
//NewWaitNode is a way to initiate a waiting no

@ -48,7 +48,7 @@ func BroadcastMessage(peers []Peer, msg []byte) {
peerCopy := peer
go send(peerCopy.Ip, peerCopy.Port, content)
}
log.Info("Broadcasting Done", "time spent(s)", time.Now().Sub(start).Seconds())
log.Info("Broadcasting Done", "time spent(s)", time.Since(start).Seconds())
}
func SelectMyPeers(peers []Peer, min int, max int) []Peer {

@ -77,10 +77,7 @@ func (req *Request) UnmarshalText(buf []byte) error {
}
req.Difficulty = uint32(diff)
req.Nonce, err = base64.RawStdEncoding.DecodeString(bits[2])
if err != nil {
return err
}
return nil
return err
}
// Convenience function to check whether a proof of work is fulfilled

@ -68,8 +68,8 @@ Response:
---- message end -----
*/
// ConsensusMessageTypeBytes is the number of bytes consensus message type occupies
const ConsensusMessageTypeBytes = 1
// MessageTypeBytes is the number of bytes consensus message type occupies
const MessageTypeBytes = 1
// ConsensusMessageType is the specific types of message under Consensus category
type ConsensusMessageType byte
@ -130,7 +130,7 @@ func GetConsensusMessagePayload(message []byte) ([]byte, error) {
if len(message) < 2 {
return []byte{}, errors.New("Failed to get consensus message payload: no data available.")
}
return message[ConsensusMessageTypeBytes:], nil
return message[MessageTypeBytes:], nil
}
// Concatenate msgType as one byte with payload, and return the whole byte array

@ -15,12 +15,9 @@ import (
type SyncPeerConfig struct {
peer p2p.Peer
conn net.Conn
block *blockchain.Block
w *bufio.Writer
receivedMsg []byte
err error
trusted bool
indexes []uint16
blockHashes [][32]byte
}

@ -74,11 +74,11 @@ func (config *DistributionConfig) GetClientPort() string {
// Parse the config file and return a 2d array containing the file data
func (config *DistributionConfig) ReadConfigFile(filename string) error {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
log.Fatal("Failed to read config file ", filename)
return err
}
defer file.Close()
fscanner := bufio.NewScanner(file)
result := []ConfigEntry{}

Loading…
Cancel
Save