fix warnings for better code

pull/1027/head
Minh Doan 5 years ago committed by Minh Doan
parent 25ce6ff59d
commit 4f5824f894
  1. 15
      core/resharding.go
  2. 48
      core/resharding_test.go
  3. 6
      internal/hmyapi/blockchain.go
  4. 2
      internal/hmyapi/sendtxargs.go

@ -212,7 +212,10 @@ func (ss *ShardingState) UpdateShardingState(stakeInfo *map[common.Address]*stru
for addr, info := range *stakeInfo {
_, ok := oldBlsPublicKeys[info.BlsPublicKey]
if !ok {
newAddresses = append(newAddresses, types.NodeID{addr, info.BlsPublicKey})
newAddresses = append(newAddresses, types.NodeID{
EcdsaAddress: addr,
BlsPublicKey: info.BlsPublicKey,
})
}
}
return newAddresses
@ -252,7 +255,10 @@ func GetShardState(epoch *big.Int) types.ShardState {
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(pub)
// TODO: directly read address for bls too
curNodeID := types.NodeID{common2.ParseAddr(hmyAccounts[index].Address), pubKey}
curNodeID := types.NodeID{
EcdsaAddress: common2.ParseAddr(hmyAccounts[index].Address),
BlsPublicKey: pubKey,
}
com.NodeList = append(com.NodeList, curNodeID)
}
@ -266,7 +272,10 @@ func GetShardState(epoch *big.Int) types.ShardState {
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(pub)
// TODO: directly read address for bls too
curNodeID := types.NodeID{common2.ParseAddr(fnAccounts[index].Address), pubKey}
curNodeID := types.NodeID{
EcdsaAddress: common2.ParseAddr(fnAccounts[index].Address),
BlsPublicKey: pubKey,
}
com.NodeList = append(com.NodeList, curNodeID)
}
shardState = append(shardState, com)

@ -48,7 +48,10 @@ func fakeGetInitShardState(numberOfShards, numOfNodes int) types.ShardState {
nid := strconv.Itoa(int(rand.Int63()))
blsPubKey := [48]byte{}
copy(blsPubKey1[:], []byte(nid))
com.NodeList = append(com.NodeList, types.NodeID{common.BytesToAddress([]byte(nid)), blsPubKey})
com.NodeList = append(com.NodeList, types.NodeID{
EcdsaAddress: common.BytesToAddress([]byte(nid)),
BlsPublicKey: blsPubKey,
})
}
shardState = append(shardState, com)
}
@ -63,7 +66,10 @@ func fakeNewNodeList(seed int64) []types.NodeID {
nid := strconv.Itoa(int(rand.Int63()))
blsPubKey := [48]byte{}
copy(blsPubKey1[:], []byte(nid))
nodeList = append(nodeList, types.NodeID{common.BytesToAddress([]byte(nid)), blsPubKey})
nodeList = append(nodeList, types.NodeID{
EcdsaAddress: common.BytesToAddress([]byte(nid)),
BlsPublicKey: blsPubKey,
})
}
return nodeList
}
@ -75,16 +81,16 @@ func TestFakeNewNodeList(t *testing.T) {
func TestShuffle(t *testing.T) {
nodeList := []types.NodeID{
{common.Address{0x12}, blsPubKey1},
{common.Address{0x22}, blsPubKey2},
{common.Address{0x32}, blsPubKey3},
{common.Address{0x42}, blsPubKey4},
{common.Address{0x52}, blsPubKey5},
{common.Address{0x62}, blsPubKey6},
{common.Address{0x72}, blsPubKey7},
{common.Address{0x82}, blsPubKey8},
{common.Address{0x92}, blsPubKey9},
{common.Address{0x02}, blsPubKey10},
{EcdsaAddress: common.Address{0x12}, BlsPublicKey: blsPubKey1},
{EcdsaAddress: common.Address{0x22}, BlsPublicKey: blsPubKey2},
{EcdsaAddress: common.Address{0x32}, BlsPublicKey: blsPubKey3},
{EcdsaAddress: common.Address{0x42}, BlsPublicKey: blsPubKey4},
{EcdsaAddress: common.Address{0x52}, BlsPublicKey: blsPubKey5},
{EcdsaAddress: common.Address{0x62}, BlsPublicKey: blsPubKey6},
{EcdsaAddress: common.Address{0x72}, BlsPublicKey: blsPubKey7},
{EcdsaAddress: common.Address{0x82}, BlsPublicKey: blsPubKey8},
{EcdsaAddress: common.Address{0x92}, BlsPublicKey: blsPubKey9},
{EcdsaAddress: common.Address{0x02}, BlsPublicKey: blsPubKey10},
}
cpList := []types.NodeID{}
@ -115,12 +121,12 @@ func TestUpdateShardState(t *testing.T) {
shardState := fakeGetInitShardState(6, 10)
ss := &ShardingState{epoch: 1, rnd: 42, shardState: shardState, numShards: len(shardState)}
newNodeList := []types.NodeID{
{common.Address{0x12}, blsPubKey1},
{common.Address{0x22}, blsPubKey2},
{common.Address{0x32}, blsPubKey3},
{common.Address{0x42}, blsPubKey4},
{common.Address{0x52}, blsPubKey5},
{common.Address{0x62}, blsPubKey6},
{EcdsaAddress: common.Address{0x12}, BlsPublicKey: blsPubKey1},
{EcdsaAddress: common.Address{0x22}, BlsPublicKey: blsPubKey2},
{EcdsaAddress: common.Address{0x32}, BlsPublicKey: blsPubKey3},
{EcdsaAddress: common.Address{0x42}, BlsPublicKey: blsPubKey4},
{EcdsaAddress: common.Address{0x52}, BlsPublicKey: blsPubKey5},
{EcdsaAddress: common.Address{0x62}, BlsPublicKey: blsPubKey6},
}
ss.Reshard(newNodeList, 0.2)
@ -131,9 +137,9 @@ func TestAssignNewNodes(t *testing.T) {
shardState := fakeGetInitShardState(2, 2)
ss := &ShardingState{epoch: 1, rnd: 42, shardState: shardState, numShards: len(shardState)}
newNodes := []types.NodeID{
{common.Address{0x12}, blsPubKey1},
{common.Address{0x22}, blsPubKey2},
{common.Address{0x32}, blsPubKey3},
{EcdsaAddress: common.Address{0x12}, BlsPublicKey: blsPubKey1},
{EcdsaAddress: common.Address{0x22}, BlsPublicKey: blsPubKey2},
{EcdsaAddress: common.Address{0x32}, BlsPublicKey: blsPubKey3},
}
ss.assignNewNodes(newNodes)

@ -19,8 +19,8 @@ import (
)
const (
defaultGasPrice = params.GWei
defaultFromtAddress = "0x1a3e7a44ee21101d7D64FBf29B0F6F1fc295F723"
defaultGasPrice = params.GWei
defaultFromAddress = "0x0000000000000000000000000000000000000000"
)
// PublicBlockChainAPI provides an API to access the Harmony blockchain.
@ -127,7 +127,7 @@ func doCall(ctx context.Context, b Backend, args CallArgs, blockNr rpc.BlockNumb
// The logic in ethereum is to pick a random address managed under the account manager.
// Currently Harmony no longers support the account manager.
// Any address does not affect the logic of this call.
addr = common.HexToAddress(defaultFromtAddress)
addr = common.HexToAddress(defaultFromAddress)
} else {
addr = *args.From
}

@ -15,7 +15,7 @@ import (
type SendTxArgs struct {
From common.Address `json:"from"`
To *common.Address `json:"to"`
ShardID uint32 `json:"shardID`
ShardID uint32 `json:"shardID"`
Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`

Loading…
Cancel
Save