From a56150a8a29e38d112e601eedfc797b4b57e0237 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sat, 20 Apr 2019 16:38:36 -0700 Subject: [PATCH 1/2] Fix getFreeToken blocking issue --- node/contract.go | 5 +++-- node/node.go | 7 ++++--- node/node_handler.go | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/node/contract.go b/node/contract.go index 02a33393b..6aa414d30 100644 --- a/node/contract.go +++ b/node/contract.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "math/big" "strings" + "sync/atomic" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -170,8 +171,8 @@ func (node *Node) CallFaucetContract(address common.Address) common.Hash { } func (node *Node) callGetFreeToken(address common.Address) common.Hash { - nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(node.ContractDeployerKey.PublicKey)) - return node.callGetFreeTokenWithNonce(address, nonce) + nonce := atomic.AddUint64(&node.ContractDeployerCurrentNonce, 1) + return node.callGetFreeTokenWithNonce(address, nonce-1) } func (node *Node) callGetFreeTokenWithNonce(address common.Address, nonce uint64) common.Hash { diff --git a/node/node.go b/node/node.go index f2b20595d..5aafad723 100644 --- a/node/node.go +++ b/node/node.go @@ -144,9 +144,10 @@ type Node struct { Address common.Address // For test only - TestBankKeys []*ecdsa.PrivateKey - ContractDeployerKey *ecdsa.PrivateKey - ContractAddresses []common.Address + TestBankKeys []*ecdsa.PrivateKey + ContractDeployerKey *ecdsa.PrivateKey + ContractDeployerCurrentNonce uint64 // The nonce of the deployer contract at current block + ContractAddresses []common.Address // Shard group Message Receiver shardGroupReceiver p2p.GroupReceiver diff --git a/node/node_handler.go b/node/node_handler.go index a7de6831e..83a17d2f9 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -11,9 +11,12 @@ import ( "os" "os/exec" "strconv" + "sync/atomic" "syscall" "time" + "github.com/ethereum/go-ethereum/crypto" + "github.com/harmony-one/harmony/core" "github.com/ethereum/go-ethereum/common" @@ -315,6 +318,10 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) { node.AddNewBlock(newBlock) + // Update contract deployer's nonce so default contract like faucet can issue transaction with current nonce + nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(node.ContractDeployerKey.PublicKey)) + atomic.StoreUint64(&node.ContractDeployerCurrentNonce, nonce) + if node.Consensus.ShardID == 0 { // ConfirmedBlockChannel which is listened by drand leader who will initiate DRG if its a epoch block (first block of a epoch) From d0d5d2396faebbfb7f602a8fa90ab929fb4da460 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 23 Apr 2019 13:59:05 -0700 Subject: [PATCH 2/2] update readme --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 72f4251e9..2076a04d7 100644 --- a/README.md +++ b/README.md @@ -127,25 +127,24 @@ See [`CONTRIBUTING`](CONTRIBUTING.md) for details. ### Features Done -- Basic consensus protocol with O(n) complexity -- Basic validator server -- P2p network connection and unicast +- Fully sharded network with beacon chain and shard chains +- Cuckoo-rule based resharding +- Staking on beacon chain +- Distributed randomness generation with VRF and VDF (Proof-of-Concept VDF) +- Sharded P2P network and P2P gossiping +- FBFT (Fast Byzantine Fault Tolerance) Consensus with BLS multi-signature - Account model and support for Solidity - Simple wallet program -- Mock beacon chain with static sharding - Information disposal algorithm using erasure encoding (to be integrated) - Blockchain explorer with performance report and transaction lookup - Transaction generator for loadtesting + ### Features To Be Implemented -- Full beacon chain with multiple validators -- Resharding -- Staking on beacon chain - Fast state synchronization -- Distributed randomness generation with VRF and VDF +- Fully implemented VDF - Kademlia routing -- P2P network and gossiping -- Full protocol of consensus with BLS multi-sig and view-change protocol +- Consensus view-change protocol - Integration with WASM - Cross-shard transaction