From 1bd5a8d606d01d422a3c343159ba85e0c54319dc Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 27 Apr 2019 19:00:56 -0700 Subject: [PATCH 01/16] Teach consensus about stake info finder StakeInfoFinder is a simple interface that makes it possible to look up a node's staking information by its consensus (BLS) or account (ECDSA) key. --- consensus/consensus.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/consensus/consensus.go b/consensus/consensus.go index d2b959207..7d817a094 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -18,6 +18,7 @@ import ( proto_discovery "github.com/harmony-one/harmony/api/proto/discovery" msg_pb "github.com/harmony-one/harmony/api/proto/message" consensus_engine "github.com/harmony-one/harmony/consensus/engine" + "github.com/harmony-one/harmony/contracts/structs" "github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/types" bls_cosi "github.com/harmony-one/harmony/crypto/bls" @@ -112,6 +113,34 @@ type Consensus struct { // The p2p host used to send/receive p2p messages host p2p.Host + + // Staking information finder + stakeInfoFinder StakeInfoFinder +} + +// StakeInfoFinder returns the stake information finder instance this +// consensus uses, e.g. for block reward distribution. +func (consensus *Consensus) StakeInfoFinder() StakeInfoFinder { + return consensus.stakeInfoFinder +} + +// SetStakeInfoFinder sets the stake information finder instance this +// consensus uses, e.g. for block reward distribution. +func (consensus *Consensus) SetStakeInfoFinder(stakeInfoFinder StakeInfoFinder) { + consensus.stakeInfoFinder = stakeInfoFinder +} + +// StakeInfoFinder finds the staking account for the given consensus key. +type StakeInfoFinder interface { + // FindStakeInfoByNodeKey returns a list of staking information matching + // the given node key. Caller may modify the returned slice of StakeInfo + // struct pointers, but must not modify the StakeInfo structs themselves. + FindStakeInfoByNodeKey(key *bls.PublicKey) []*structs.StakeInfo + + // FindStakeInfoByAccount returns a list of staking information matching + // the given account. Caller may modify the returned slice of StakeInfo + // struct pointers, but must not modify the StakeInfo structs themselves. + FindStakeInfoByAccount(addr common.Address) []*structs.StakeInfo } // BlockConsensusStatus used to keep track of the consensus status of multiple blocks received so far From 5c74aa5899657bc317d28624fba391d1021205f4 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 10:35:03 -0700 Subject: [PATCH 02/16] Colocate the Hex method with the receiver --- core/types/shard_state.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/types/shard_state.go b/core/types/shard_state.go index a160bb454..4816c47ba 100644 --- a/core/types/shard_state.go +++ b/core/types/shard_state.go @@ -21,6 +21,11 @@ type ShardState []Committee // BlsPublicKey defines the bls public key type BlsPublicKey [96]byte +// Hex returns the hex string of bls public key +func (pk BlsPublicKey) Hex() string { + return hex.EncodeToString(pk[:]) +} + // NodeID represents node id (BLS address). type NodeID struct { EcdsaAddress string @@ -34,11 +39,6 @@ type Committee struct { NodeList []NodeID } -// Hex returns the hex string of bls public key -func (pk BlsPublicKey) Hex() string { - return hex.EncodeToString(pk[:]) -} - // GetHashFromNodeList will sort the list, then use Keccak256 to hash the list // notice that the input nodeList will be modified (sorted) func GetHashFromNodeList(nodeList []NodeID) []byte { From 0a498ea735071984988d671e975124de3a0fa7ce Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 10:35:44 -0700 Subject: [PATCH 03/16] Add conversion methods to BlsPublicKey --- core/types/shard_state.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/types/shard_state.go b/core/types/shard_state.go index 4816c47ba..0b08f3415 100644 --- a/core/types/shard_state.go +++ b/core/types/shard_state.go @@ -6,7 +6,10 @@ import ( "sort" "github.com/ethereum/go-ethereum/common" + "github.com/harmony-one/bls/ffi/go/bls" "golang.org/x/crypto/sha3" + + "github.com/harmony-one/harmony/internal/ctxerror" ) // EpochShardState is the shard state of an epoch @@ -26,6 +29,23 @@ func (pk BlsPublicKey) Hex() string { return hex.EncodeToString(pk[:]) } +// FromLibBLSPublicKey replaces the key contents with the given key, +func (pk *BlsPublicKey) FromLibBLSPublicKey(key *bls.PublicKey) error { + bytes := key.Serialize() + if len(bytes) != len(pk) { + return ctxerror.New("BLS public key size mismatch", + "expected", len(pk), + "actual", len(bytes)) + } + copy(pk[:], bytes) + return nil +} + +// ToLibBLSPublicKey copies the key contents into the given key. +func (pk *BlsPublicKey) ToLibBLSPublicKey(key *bls.PublicKey) error { + return key.Deserialize(pk[:]) +} + // NodeID represents node id (BLS address). type NodeID struct { EcdsaAddress string From c396ee5f1a5a8f841e3e87c72db7164b1864765a Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 10:37:22 -0700 Subject: [PATCH 04/16] =?UTF-8?q?Rename=20consensus=20=E2=86=92=20currentC?= =?UTF-8?q?onsensus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to un-shadow the consensus package. --- cmd/harmony/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 3c502c422..45efef0c9 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -197,20 +197,20 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // Consensus object. // TODO: consensus object shouldn't start here // TODO(minhdoan): During refactoring, found out that the peers list is actually empty. Need to clean up the logic of consensus later. - consensus, err := consensus.New(nodeConfig.Host, nodeConfig.ShardID, nodeConfig.Leader, nodeConfig.ConsensusPriKey) + currentConsensus, err := consensus.New(nodeConfig.Host, nodeConfig.ShardID, nodeConfig.Leader, nodeConfig.ConsensusPriKey) if err != nil { fmt.Fprintf(os.Stderr, "Error :%v \n", err) os.Exit(1) } - consensus.MinPeers = *minPeers + currentConsensus.MinPeers = *minPeers // Current node. - currentNode := node.New(nodeConfig.Host, consensus, nodeConfig.MainDB, *isArchival) + currentNode := node.New(nodeConfig.Host, currentConsensus, nodeConfig.MainDB, *isArchival) currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.AccountKey = nodeConfig.StakingPriKey // TODO: refactor the creation of blockchain out of node.New() - consensus.ChainReader = currentNode.Blockchain() + currentConsensus.ChainReader = currentNode.Blockchain() if *isGenesis { // TODO: need change config file and use switch instead of complicated "if else" condition @@ -259,7 +259,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen currentNode.Consensus.RegisterRndChannel(dRand.RndChannel) currentNode.DRand = dRand - if consensus.ShardID != 0 { + if currentConsensus.ShardID != 0 { currentNode.AddBeaconChainDatabase(nodeConfig.BeaconDB) } // This needs to be executed after consensus and drand are setup @@ -268,14 +268,14 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // Set the consensus ID to be the current block number height := currentNode.Blockchain().CurrentBlock().NumberU64() - consensus.SetConsensusID(uint32(height)) + currentConsensus.SetConsensusID(uint32(height)) utils.GetLogInstance().Info("Init Blockchain", "height", height) // Assign closure functions to the consensus object - consensus.BlockVerifier = currentNode.VerifyNewBlock - consensus.OnConsensusDone = currentNode.PostConsensusProcessing + currentConsensus.BlockVerifier = currentNode.VerifyNewBlock + currentConsensus.OnConsensusDone = currentNode.PostConsensusProcessing currentNode.State = node.NodeWaitToJoin - return consensus, currentNode + return currentConsensus, currentNode } func main() { From 75a92d7b109dcc94642443d3655de1112cd0a84c Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 11:42:51 -0700 Subject: [PATCH 05/16] Add field names to StakeInfo field init --- node/staking.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node/staking.go b/node/staking.go index 4b8922c18..4d7fff8fe 100644 --- a/node/staking.go +++ b/node/staking.go @@ -51,10 +51,10 @@ func (node *Node) UpdateStakingList(stakeInfoReturnValue *structs.StakeInfoRetur copy(blsPubKey[32:64], stakeInfoReturnValue.BlsPubicKeys2[i][:]) copy(blsPubKey[64:96], stakeInfoReturnValue.BlsPubicKeys2[i][:]) node.CurrentStakes[addr] = &structs.StakeInfo{ - blsPubKey, - blockNum, - lockPeriodCount, - stakeInfoReturnValue.Amounts[i], + BlsPublicKey: blsPubKey, + BlockNum: blockNum, + LockPeriodCount: lockPeriodCount, + Amount: stakeInfoReturnValue.Amounts[i], } } } From e9d1324ecc589b2037ba01de698b2be56866a3a0 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 11:44:17 -0700 Subject: [PATCH 06/16] Add account address to StakeInfo --- contracts/structs/structs.go | 1 + node/staking.go | 1 + 2 files changed, 2 insertions(+) diff --git a/contracts/structs/structs.go b/contracts/structs/structs.go index 4251175b7..7feebf387 100644 --- a/contracts/structs/structs.go +++ b/contracts/structs/structs.go @@ -21,6 +21,7 @@ type StakeInfoReturnValue struct { // StakeInfo stores the staking information for a staker. type StakeInfo struct { + Account common.Address BlsPublicKey types.BlsPublicKey BlockNum *big.Int LockPeriodCount *big.Int // The number of locking period the token will be locked. diff --git a/node/staking.go b/node/staking.go index 4d7fff8fe..aa55cc9db 100644 --- a/node/staking.go +++ b/node/staking.go @@ -51,6 +51,7 @@ func (node *Node) UpdateStakingList(stakeInfoReturnValue *structs.StakeInfoRetur copy(blsPubKey[32:64], stakeInfoReturnValue.BlsPubicKeys2[i][:]) copy(blsPubKey[64:96], stakeInfoReturnValue.BlsPubicKeys2[i][:]) node.CurrentStakes[addr] = &structs.StakeInfo{ + Account: addr, BlsPublicKey: blsPubKey, BlockNum: blockNum, LockPeriodCount: lockPeriodCount, From 9796df0dd90b27d45637418a7de3895a9c5d7cd7 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 11:44:50 -0700 Subject: [PATCH 07/16] Add a simple StakeInfo finder covering genesis nodes --- consensus/consensus.go | 87 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index 7d817a094..52c76e591 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -7,14 +7,19 @@ import ( "encoding/hex" "errors" "fmt" + "math/big" "reflect" "sync" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" protobuf "github.com/golang/protobuf/proto" "github.com/harmony-one/bls/ffi/go/bls" + libp2p_peer "github.com/libp2p/go-libp2p-peer" + "golang.org/x/crypto/sha3" + proto_discovery "github.com/harmony-one/harmony/api/proto/discovery" msg_pb "github.com/harmony-one/harmony/api/proto/message" consensus_engine "github.com/harmony-one/harmony/consensus/engine" @@ -22,11 +27,11 @@ import ( "github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/types" bls_cosi "github.com/harmony-one/harmony/crypto/bls" + "github.com/harmony-one/harmony/internal/ctxerror" "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/internal/utils/contract" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/host" - libp2p_peer "github.com/libp2p/go-libp2p-peer" - "golang.org/x/crypto/sha3" ) // Consensus is the main struct with all states and data related to consensus process. @@ -703,3 +708,81 @@ func (consensus *Consensus) GetNodeIDs() []libp2p_peer.ID { func (consensus *Consensus) GetConsensusID() uint32 { return consensus.consensusID } + +// GenesisStakeInfoFinder is a stake info finder implementation using only +// genesis accounts. +// When used for block reward, it rewards only foundational nodes. +type GenesisStakeInfoFinder struct { + byNodeKey map[types.BlsPublicKey][]*structs.StakeInfo + byAccount map[common.Address][]*structs.StakeInfo +} + +// FindStakeInfoByNodeKey returns the genesis account matching the given node +// key, as a single-item StakeInfo list. +// It returns nil if the key is not a genesis node key. +func (f *GenesisStakeInfoFinder) FindStakeInfoByNodeKey( + key *bls.PublicKey, +) []*structs.StakeInfo { + var pk types.BlsPublicKey + if err := pk.FromLibBLSPublicKey(key); err != nil { + ctxerror.Log15(utils.GetLogInstance().Warn, ctxerror.New( + "cannot convert BLS public key", + ).WithCause(err)) + return nil + } + l, _ := f.byNodeKey[pk] + return l +} + +// FindStakeInfoByAccount returns the genesis account matching the given +// address, as a single-item StakeInfo list. +// It returns nil if the address is not a genesis account. +func (f *GenesisStakeInfoFinder) FindStakeInfoByAccount( + addr common.Address, +) []*structs.StakeInfo { + l, _ := f.byAccount[addr] + return l +} + +// NewGenesisStakeInfoFinder returns a stake info finder that can look up +// genesis nodes. +func NewGenesisStakeInfoFinder() (*GenesisStakeInfoFinder, error) { + f := &GenesisStakeInfoFinder{ + byNodeKey: make(map[types.BlsPublicKey][]*structs.StakeInfo), + byAccount: make(map[common.Address][]*structs.StakeInfo), + } + for idx, account := range contract.GenesisAccounts { + blsSecretKeyHex := contract.GenesisBLSAccounts[idx].Private + blsSecretKey := bls.SecretKey{} + if err := blsSecretKey.SetHexString(blsSecretKeyHex); err != nil { + return nil, ctxerror.New("cannot convert BLS secret key", + "accountIndex", idx, + ).WithCause(err) + } + pub := blsSecretKey.GetPublicKey() + var blsPublicKey types.BlsPublicKey + if err := blsPublicKey.FromLibBLSPublicKey(pub); err != nil { + return nil, ctxerror.New("cannot convert BLS public key", + "accountIndex", idx, + ).WithCause(err) + } + addressBytes, err := hexutil.Decode(account.Address) + if err != nil { + return nil, ctxerror.New("cannot decode account address", + "accountIndex", idx, + ).WithCause(err) + } + var address common.Address + address.SetBytes(addressBytes) + stakeInfo := &structs.StakeInfo{ + Account: address, + BlsPublicKey: blsPublicKey, + BlockNum: common.Big0, + LockPeriodCount: big.NewInt(0x7fffffffffffffff), + Amount: common.Big0, + } + f.byNodeKey[blsPublicKey] = append(f.byNodeKey[blsPublicKey], stakeInfo) + f.byAccount[address] = append(f.byAccount[address], stakeInfo) + } + return f, nil +} From e79a42e26da1903e036afdb2e549317c7ac42b93 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 11:45:56 -0700 Subject: [PATCH 08/16] Plug genesis stake info finder into harmony/txgen --- cmd/client/txgen/main.go | 12 +++++++++++- cmd/harmony/main.go | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index 9e9de23d9..61f033dbe 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -111,6 +111,12 @@ func main() { ) log.Root().SetHandler(h) + gsif, err := consensus.NewGenesisStakeInfoFinder() + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Cannot initialize stake info: %v\n", err) + os.Exit(1) + } + // Nodes containing blockchain data to mirror the shards' data in the network nodes := []*node.Node{} host, err := p2pimpl.NewHost(&selfPeer, nodePriKey) @@ -118,7 +124,9 @@ func main() { panic("unable to new host in txgen") } for _, shardID := range shardIDs { - node := node.New(host, &consensus.Consensus{ShardID: shardID}, nil, false) + c := &consensus.Consensus{ShardID: shardID} + node := node.New(host, c, nil, false) + c.SetStakeInfoFinder(gsif) // Assign many fake addresses so we have enough address to play with at first nodes = append(nodes, node) } @@ -133,6 +141,8 @@ func main() { clientNode := node.New(host, consensusObj, nil, false) clientNode.Client = client.NewClient(clientNode.GetHost(), shardIDs) + consensusObj.SetStakeInfoFinder(gsif) + readySignal := make(chan uint32) // This func is used to update the client's blockchain when new blocks are received from the leaders diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 45efef0c9..d107ed992 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -209,6 +209,13 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.AccountKey = nodeConfig.StakingPriKey + if gsif, err := consensus.NewGenesisStakeInfoFinder(); err == nil { + currentConsensus.SetStakeInfoFinder(gsif) + } else { + _, _ = fmt.Fprintf(os.Stderr, "Cannot initialize stake info: %v\n", err) + os.Exit(1) + } + // TODO: refactor the creation of blockchain out of node.New() currentConsensus.ChainReader = currentNode.Blockchain() From 2647b3101d1b5819bc6b0dcba235fbd8b0a1032b Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 14:52:25 -0700 Subject: [PATCH 09/16] Reward foundational nodes for signing blocks --- consensus/consensus.go | 63 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index 52c76e591..b07769551 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -34,6 +34,12 @@ import ( "github.com/harmony-one/harmony/p2p/host" ) +// Block reward per block signature. +// TODO ek – per sig per stake +var ( + BlockReward = big.NewInt(params.Ether / 1000) +) + // Consensus is the main struct with all states and data related to consensus process. type Consensus struct { // The current state of the consensus @@ -598,7 +604,10 @@ func (consensus *Consensus) VerifySeal(chain consensus_engine.ChainReader, heade func (consensus *Consensus) Finalize(chain consensus_engine.ChainReader, header *types.Header, state *state.DB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error) { // Accumulate any block and uncle rewards and commit the final state root // Header seems complete, assemble into a block and return - accumulateRewards(chain.Config(), state, header) + err := consensus.accumulateRewards(chain.Config(), state, header) + if err != nil { + ctxerror.Log15(utils.GetLogInstance().Error, err) + } header.Root = state.IntermediateRoot(false) return types.NewBlock(header, txs, receipts), nil } @@ -641,8 +650,56 @@ func (consensus *Consensus) Prepare(chain consensus_engine.ChainReader, header * // AccumulateRewards credits the coinbase of the given block with the mining // reward. The total reward consists of the static block reward and rewards for // included uncles. The coinbase of each uncle block is also rewarded. -func accumulateRewards(config *params.ChainConfig, state *state.DB, header *types.Header) { - // TODO: implement mining rewards +func (consensus *Consensus) accumulateRewards( + config *params.ChainConfig, state *state.DB, header *types.Header, +) error { + logger := utils.GetLogInstance().New("parentHash", header.ParentHash) + if header.ParentHash == (common.Hash{}) { + // This block is a genesis block, + // without a parent block whose signer to reward. + return nil + } + if consensus.ChainReader == nil { + return errors.New("ChainReader is nil") + } + parent := consensus.ChainReader.GetHeaderByHash(header.ParentHash) + if parent == nil { + return ctxerror.New("cannot retrieve parent header", + "parentHash", header.ParentHash, + ) + } + mask, err := bls_cosi.NewMask(consensus.PublicKeys, nil) + if err != nil { + return ctxerror.New("cannot create group sig mask").WithCause(err) + } + logger.Debug("accumulateRewards: setting group sig mask", + "destLen", mask.Len(), + "srcLen", len(parent.CommitBitmap), + ) + if err := mask.SetMask(parent.CommitBitmap); err != nil { + return ctxerror.New("cannot set group sig mask bits").WithCause(err) + } + totalAmount := big.NewInt(0) + numAccounts := 0 + signingKeys := mask.GetPubKeyFromMask(true) + for _, key := range signingKeys { + stakeInfos := consensus.stakeInfoFinder.FindStakeInfoByNodeKey(key) + if len(stakeInfos) == 0 { + logger.Error("accumulateRewards: node has no stake info", + "nodeKey", key.GetHexString()) + continue + } + numAccounts += len(stakeInfos) + for _, stakeInfo := range stakeInfos { + state.AddBalance(stakeInfo.Account, BlockReward) + totalAmount = new(big.Int).Add(totalAmount, BlockReward) + } + } + logger.Debug("accumulateRewards: paid out block reward", + "numSigs", len(signingKeys), + "numAccounts", numAccounts, + "totalAmount", totalAmount) + return nil } // GetSelfAddress returns the address in hex From 0364fa422b07bbb3d91a16d918ae163cd213b578 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 1 Apr 2019 18:59:51 -0700 Subject: [PATCH 10/16] Log who earns how much for signing what block --- consensus/consensus.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/consensus/consensus.go b/consensus/consensus.go index b07769551..b0b64783b 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -691,6 +691,11 @@ func (consensus *Consensus) accumulateRewards( } numAccounts += len(stakeInfos) for _, stakeInfo := range stakeInfos { + utils.GetLogInstance().Info("accumulateRewards: rewarding", + "block", header.Hash(), + "account", stakeInfo.Account, + "node", stakeInfo.BlsPublicKey.Hex(), + "amount", BlockReward) state.AddBalance(stakeInfo.Account, BlockReward) totalAmount = new(big.Int).Add(totalAmount, BlockReward) } From c31759cfd59898593373cd8927d0df51e438f28a Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 1 Apr 2019 19:19:16 -0700 Subject: [PATCH 11/16] Remove unused address field --- node/node.go | 1 - 1 file changed, 1 deletion(-) diff --git a/node/node.go b/node/node.go index 57ddb77c2..e6da7ae59 100644 --- a/node/node.go +++ b/node/node.go @@ -141,7 +141,6 @@ type Node struct { //Node Account AccountKey *ecdsa.PrivateKey - Address common.Address // For test only TestBankKeys []*ecdsa.PrivateKey From 5e2ab2fbf204cb52c8b318b58afe45d5309d369b Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 1 Apr 2019 19:23:35 -0700 Subject: [PATCH 12/16] Log node account address --- cmd/harmony/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index d107ed992..0862731da 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -11,6 +11,7 @@ import ( "github.com/harmony-one/harmony/core" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" @@ -208,6 +209,8 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen currentNode := node.New(nodeConfig.Host, currentConsensus, nodeConfig.MainDB, *isArchival) currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.AccountKey = nodeConfig.StakingPriKey + utils.GetLogInstance().Info("node account set", + "address", crypto.PubkeyToAddress(currentNode.AccountKey.PublicKey)) if gsif, err := consensus.NewGenesisStakeInfoFinder(); err == nil { currentConsensus.SetStakeInfoFinder(gsif) From 78a554d28e77ee786b56866180f1f314481857bc Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 15:19:39 -0700 Subject: [PATCH 13/16] Reorganize imports into stdlib-remote-local format --- cmd/harmony/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 0862731da..0c75d4215 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -9,14 +9,13 @@ import ( "runtime" "time" - "github.com/harmony-one/harmony/core" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" - "github.com/harmony-one/bls/ffi/go/bls" + "github.com/harmony-one/harmony/consensus" + "github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/drand" nodeconfig "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/profiler" From 4ad7a1d5a49e4886ee3bf95013ea9ef5c3201e59 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 16:39:48 -0700 Subject: [PATCH 14/16] Teach txgen to use ChainReader for block rewards --- cmd/client/txgen/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index 61f033dbe..c59b9ebb6 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -127,6 +127,7 @@ func main() { c := &consensus.Consensus{ShardID: shardID} node := node.New(host, c, nil, false) c.SetStakeInfoFinder(gsif) + c.ChainReader = node.Blockchain() // Assign many fake addresses so we have enough address to play with at first nodes = append(nodes, node) } @@ -142,6 +143,7 @@ func main() { clientNode.Client = client.NewClient(clientNode.GetHost(), shardIDs) consensusObj.SetStakeInfoFinder(gsif) + consensusObj.ChainReader = clientNode.Blockchain() readySignal := make(chan uint32) From 79f503a724991d63528e0339254d4ff7d78f2657 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 29 Apr 2019 16:40:26 -0700 Subject: [PATCH 15/16] Initialize shard keys in txgen --- cmd/client/txgen/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index c59b9ebb6..055e204d8 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -9,7 +9,10 @@ import ( "sync" "time" + bls2 "github.com/harmony-one/bls/ffi/go/bls" + "github.com/harmony-one/harmony/core" + "github.com/harmony-one/harmony/internal/utils/contract" "github.com/harmony-one/harmony/crypto/bls" @@ -128,6 +131,19 @@ func main() { node := node.New(host, c, nil, false) c.SetStakeInfoFinder(gsif) c.ChainReader = node.Blockchain() + // Replace public keys with genesis accounts for the shard + c.PublicKeys = nil + startIdx := core.GenesisShardSize * shardID + endIdx := startIdx + core.GenesisShardSize + for _, acct := range contract.GenesisBLSAccounts[startIdx:endIdx] { + secretKey := bls2.SecretKey{} + if err := secretKey.SetHexString(acct.Private); err != nil { + _, _ = fmt.Fprintf(os.Stderr, "cannot parse secret key: %v\n", + err) + os.Exit(1) + } + c.PublicKeys = append(c.PublicKeys, secretKey.GetPublicKey()) + } // Assign many fake addresses so we have enough address to play with at first nodes = append(nodes, node) } From 485127cfbac93b99f545afbfee57f18229630e8d Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Tue, 30 Apr 2019 11:00:23 -0700 Subject: [PATCH 16/16] =?UTF-8?q?Change=20block=20reward=200.001=20?= =?UTF-8?q?=E2=86=92=200.1=20HRX/sig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested-by: Leo Chen --- consensus/consensus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index b0b64783b..357774175 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -37,7 +37,7 @@ import ( // Block reward per block signature. // TODO ek – per sig per stake var ( - BlockReward = big.NewInt(params.Ether / 1000) + BlockReward = big.NewInt(params.Ether / 10) ) // Consensus is the main struct with all states and data related to consensus process.