From 32c29e29f97f80da14fc37b521f18e777f38db07 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 2 Nov 2020 18:16:05 -0800 Subject: [PATCH 1/6] Revert "remove beacon sync for explorer node" This reverts commit 13051c4cf8fa5562376db10135234f3bc371aef6. --- cmd/harmony/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index bd078f765..07971a601 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -315,7 +315,7 @@ func setupNodeAndRun(hc harmonyConfig) { WSPort: hc.WS.Port, DebugEnabled: hc.RPCOpt.DebugEnabled, } - if nodeConfig.ShardID != shard.BeaconChainShardID && hc.General.NodeType != nodeTypeExplorer { + if nodeConfig.ShardID != shard.BeaconChainShardID { utils.Logger().Info(). Uint32("shardID", currentNode.Blockchain().ShardID()). Uint32("shardID", nodeConfig.ShardID).Msg("SupportBeaconSyncing") From 4d18b7feec441926ae437489325765e1782fa4bf Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 2 Nov 2020 18:48:51 -0800 Subject: [PATCH 2/6] Revert "Fix view change stuck issue" --- consensus/consensus_service.go | 10 ++-------- consensus/consensus_v2.go | 2 +- consensus/construct_test.go | 10 ++++------ consensus/quorum/one-node-one-vote.go | 2 +- consensus/quorum/one-node-staked-vote.go | 2 +- consensus/quorum/quorom_test.go | 14 +++++++------- consensus/quorum/quorum.go | 6 ++---- consensus/validator.go | 19 ++++++++----------- consensus/view_change.go | 5 +++-- 9 files changed, 29 insertions(+), 41 deletions(-) diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index b3ede1404..17a220de0 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -421,12 +421,6 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { Msg("[UpdateConsensusInformation] changing committee") // take care of possible leader change during the epoch - // TODO: in a very rare case, when a M1 view change happened, the block contains coinbase for last leader - // but the new leader is actually recognized by most of the nodes. At this time, if a node sync to this - // exact block and set its leader, it will set with the failed leader as in the coinbase of the block. - // This is a very rare case scenario and not likely to cause any issue in mainnet. But we need to think about - // a solution to take care of this case because the coinbase of the latest block doesn't really represent the - // the real current leader in case of M1 view change. if !curHeader.IsLastBlockInEpoch() && curHeader.Number().Uint64() != 0 { leaderPubKey, err := consensus.getLeaderPubKeyFromCoinbase(curHeader) if err != nil || leaderPubKey == nil { @@ -579,9 +573,9 @@ func (consensus *Consensus) selfCommit(payload []byte) error { continue } - if _, err := consensus.Decider.AddNewVote( + if _, err := consensus.Decider.SubmitVote( quorum.Commit, - []*bls_cosi.PublicKeyWrapper{key.Pub}, + []bls.SerializedPublicKey{key.Pub.Bytes}, key.Pri.SignHash(commitPayload), common.BytesToHash(consensus.blockHash[:]), block.NumberU64(), diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index ea1d1b9a0..6360d77a0 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -517,7 +517,7 @@ func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMess } atomic.AddUint64(&consensus.blockNum, 1) - consensus.SetViewIDs(committedMsg.ViewID + 1) + consensus.SetCurBlockViewID(committedMsg.ViewID + 1) consensus.LeaderPubKey = committedMsg.SenderPubkeys[0] // Update consensus keys at last so the change of leader status doesn't mess up normal flow if blk.IsLastBlockInEpoch() { diff --git a/consensus/construct_test.go b/consensus/construct_test.go index 27d1e82f4..24b45c11a 100644 --- a/consensus/construct_test.go +++ b/consensus/construct_test.go @@ -71,21 +71,19 @@ func TestConstructPreparedMessage(test *testing.T) { message := "test string" leaderKey := bls.SerializedPublicKey{} leaderKey.FromLibBLSPublicKey(leaderPubKey) - leaderKeyWrapper := bls.PublicKeyWrapper{Object: leaderPubKey, Bytes: leaderKey} validatorKey := bls.SerializedPublicKey{} validatorKey.FromLibBLSPublicKey(validatorPubKey) - validatorKeyWrapper := bls.PublicKeyWrapper{Object: validatorPubKey, Bytes: validatorKey} - consensus.Decider.AddNewVote( + consensus.Decider.SubmitVote( quorum.Prepare, - []*bls.PublicKeyWrapper{&leaderKeyWrapper}, + []bls.SerializedPublicKey{leaderKey}, leaderPriKey.Sign(message), common.BytesToHash(consensus.blockHash[:]), consensus.blockNum, consensus.GetCurBlockViewID(), ) - if _, err := consensus.Decider.AddNewVote( + if _, err := consensus.Decider.SubmitVote( quorum.Prepare, - []*bls.PublicKeyWrapper{&validatorKeyWrapper}, + []bls.SerializedPublicKey{validatorKey}, validatorPriKey.Sign(message), common.BytesToHash(consensus.blockHash[:]), consensus.blockNum, diff --git a/consensus/quorum/one-node-one-vote.go b/consensus/quorum/one-node-one-vote.go index 7455d6e72..45db9bcd3 100644 --- a/consensus/quorum/one-node-one-vote.go +++ b/consensus/quorum/one-node-one-vote.go @@ -36,7 +36,7 @@ func (v *uniformVoteWeight) AddNewVote( for i, pubKey := range pubKeys { pubKeysBytes[i] = pubKey.Bytes } - return v.submitVote(p, pubKeysBytes, sig, headerHash, height, viewID) + return v.SubmitVote(p, pubKeysBytes, sig, headerHash, height, viewID) } // IsQuorumAchieved .. diff --git a/consensus/quorum/one-node-staked-vote.go b/consensus/quorum/one-node-staked-vote.go index 0f65257c9..8023b03d8 100644 --- a/consensus/quorum/one-node-staked-vote.go +++ b/consensus/quorum/one-node-staked-vote.go @@ -82,7 +82,7 @@ func (v *stakedVoteWeight) AddNewVote( pubKeysBytes[i] = pubKey.Bytes } - ballet, err := v.submitVote(p, pubKeysBytes, sig, headerHash, height, viewID) + ballet, err := v.SubmitVote(p, pubKeysBytes, sig, headerHash, height, viewID) if err != nil { return ballet, err diff --git a/consensus/quorum/quorom_test.go b/consensus/quorum/quorom_test.go index 73767ea25..d6b91a5bf 100644 --- a/consensus/quorum/quorom_test.go +++ b/consensus/quorum/quorom_test.go @@ -88,7 +88,7 @@ func TestSubmitVote(test *testing.T) { decider.UpdateParticipants([]bls.PublicKeyWrapper{pubKeyWrapper1, pubKeyWrapper2}) - if _, err := decider.submitVote( + if _, err := decider.SubmitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper1.Bytes}, blsPriKey1.Sign(message), @@ -99,7 +99,7 @@ func TestSubmitVote(test *testing.T) { test.Log(err) } - if _, err := decider.submitVote( + if _, err := decider.SubmitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes}, blsPriKey2.Sign(message), @@ -110,7 +110,7 @@ func TestSubmitVote(test *testing.T) { test.Log(err) } if decider.SignersCount(Prepare) != 2 { - test.Fatal("submitVote failed") + test.Fatal("SubmitVote failed") } aggSig := &bls_core.Sign{} @@ -145,7 +145,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { decider.UpdateParticipants([]bls.PublicKeyWrapper{pubKeyWrapper1, pubKeyWrapper2}) - decider.submitVote( + decider.SubmitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper1.Bytes}, blsPriKey1.SignHash(blockHash[:]), @@ -160,7 +160,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { aggSig.Add(s) } } - if _, err := decider.submitVote( + if _, err := decider.SubmitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes, pubKeyWrapper3.Bytes}, aggSig, @@ -172,7 +172,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { } if decider.SignersCount(Prepare) != 3 { - test.Fatal("submitVote failed") + test.Fatal("SubmitVote failed") } aggSig.Add(blsPriKey1.SignHash(blockHash[:])) @@ -180,7 +180,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { test.Fatal("AggregateVotes failed") } - if _, err := decider.submitVote( + if _, err := decider.SubmitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes}, aggSig, diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index 674ea96c0..f41d47ec1 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -81,8 +81,7 @@ type ParticipantTracker interface { // SignatoryTracker .. type SignatoryTracker interface { ParticipantTracker - // This func shouldn't be called directly from outside of quorum. Use AddNewVote instead. - submitVote( + SubmitVote( p Phase, pubkeys []bls.SerializedPublicKey, sig *bls_core.Sign, headerHash common.Hash, height, viewID uint64, @@ -119,7 +118,6 @@ type Decider interface { DependencyInjectionWriter SetVoters(subCommittee *shard.Committee, epoch *big.Int) (*TallyResult, error) Policy() Policy - // Add new vote will add the signature in the memory and increase the cumulative voting power AddNewVote( p Phase, pubkeys []*bls_cosi.PublicKeyWrapper, sig *bls_core.Sign, headerHash common.Hash, @@ -275,7 +273,7 @@ func (s *cIdentities) SignersCount(p Phase) int64 { } } -func (s *cIdentities) submitVote( +func (s *cIdentities) SubmitVote( p Phase, pubkeys []bls.SerializedPublicKey, sig *bls_core.Sign, headerHash common.Hash, height, viewID uint64, diff --git a/consensus/validator.go b/consensus/validator.go index 3837ddda4..3dd3f03f8 100644 --- a/consensus/validator.go +++ b/consensus/validator.go @@ -114,6 +114,10 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) { Msg("Wrong BlockNum Received, ignoring!") return } + if recvMsg.BlockNum > consensus.blockNum { + consensus.getLogger().Warn().Msgf("[OnPrepared] low consensus block number. Spin sync") + consensus.spinUpStateSync() + } // check validity of prepared signature blockHash := recvMsg.BlockHash @@ -149,12 +153,6 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) { if !consensus.onPreparedSanityChecks(&blockObj, recvMsg) { return } - - if recvMsg.BlockNum > consensus.blockNum { - consensus.getLogger().Warn().Msgf("[OnPrepared] low consensus block number. Spin sync") - consensus.spinUpStateSync() - } - consensus.mutex.Lock() defer consensus.mutex.Unlock() @@ -238,6 +236,10 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) { if !consensus.isRightBlockNumCheck(recvMsg) { return } + if recvMsg.BlockNum > consensus.blockNum { + consensus.getLogger().Info().Msg("[OnCommitted] low consensus block number. Spin up state sync") + consensus.spinUpStateSync() + } aggSig, mask, err := consensus.ReadSignatureBitmapPayload(recvMsg.Payload, 0) if err != nil { @@ -270,11 +272,6 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) { consensus.FBFTLog.AddMessage(recvMsg) - if recvMsg.BlockNum > consensus.blockNum { - consensus.getLogger().Info().Msg("[OnCommitted] low consensus block number. Spin up state sync") - consensus.spinUpStateSync() - } - consensus.mutex.Lock() defer consensus.mutex.Unlock() diff --git a/consensus/view_change.go b/consensus/view_change.go index 3ef66eb9d..37df69712 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -131,8 +131,9 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) { if curTimestamp <= blockTimestamp { return consensus.fallbackNextViewID() } - // diff only increases - diff := uint64((curTimestamp - blockTimestamp) / viewChangeTimeout) + totalNode := consensus.Decider.ParticipantsCount() + // diff is at least 1, and it won't exceed the totalNode + diff := uint64(((curTimestamp - blockTimestamp) / viewChangeTimeout) % int64(totalNode)) nextViewID := diff + consensus.GetCurBlockViewID() consensus.getLogger().Info(). From a5b40666fd58a3b733015b81e14c7c4e5b900f82 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 2 Nov 2020 21:49:01 -0800 Subject: [PATCH 3/6] fix self commit voting --- consensus/consensus_service.go | 10 ++++++++-- consensus/construct_test.go | 10 ++++++---- consensus/quorum/one-node-one-vote.go | 2 +- consensus/quorum/one-node-staked-vote.go | 2 +- consensus/quorum/quorom_test.go | 14 +++++++------- consensus/quorum/quorum.go | 3 ++- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index 17a220de0..b3ede1404 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -421,6 +421,12 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { Msg("[UpdateConsensusInformation] changing committee") // take care of possible leader change during the epoch + // TODO: in a very rare case, when a M1 view change happened, the block contains coinbase for last leader + // but the new leader is actually recognized by most of the nodes. At this time, if a node sync to this + // exact block and set its leader, it will set with the failed leader as in the coinbase of the block. + // This is a very rare case scenario and not likely to cause any issue in mainnet. But we need to think about + // a solution to take care of this case because the coinbase of the latest block doesn't really represent the + // the real current leader in case of M1 view change. if !curHeader.IsLastBlockInEpoch() && curHeader.Number().Uint64() != 0 { leaderPubKey, err := consensus.getLeaderPubKeyFromCoinbase(curHeader) if err != nil || leaderPubKey == nil { @@ -573,9 +579,9 @@ func (consensus *Consensus) selfCommit(payload []byte) error { continue } - if _, err := consensus.Decider.SubmitVote( + if _, err := consensus.Decider.AddNewVote( quorum.Commit, - []bls.SerializedPublicKey{key.Pub.Bytes}, + []*bls_cosi.PublicKeyWrapper{key.Pub}, key.Pri.SignHash(commitPayload), common.BytesToHash(consensus.blockHash[:]), block.NumberU64(), diff --git a/consensus/construct_test.go b/consensus/construct_test.go index 24b45c11a..27d1e82f4 100644 --- a/consensus/construct_test.go +++ b/consensus/construct_test.go @@ -71,19 +71,21 @@ func TestConstructPreparedMessage(test *testing.T) { message := "test string" leaderKey := bls.SerializedPublicKey{} leaderKey.FromLibBLSPublicKey(leaderPubKey) + leaderKeyWrapper := bls.PublicKeyWrapper{Object: leaderPubKey, Bytes: leaderKey} validatorKey := bls.SerializedPublicKey{} validatorKey.FromLibBLSPublicKey(validatorPubKey) - consensus.Decider.SubmitVote( + validatorKeyWrapper := bls.PublicKeyWrapper{Object: validatorPubKey, Bytes: validatorKey} + consensus.Decider.AddNewVote( quorum.Prepare, - []bls.SerializedPublicKey{leaderKey}, + []*bls.PublicKeyWrapper{&leaderKeyWrapper}, leaderPriKey.Sign(message), common.BytesToHash(consensus.blockHash[:]), consensus.blockNum, consensus.GetCurBlockViewID(), ) - if _, err := consensus.Decider.SubmitVote( + if _, err := consensus.Decider.AddNewVote( quorum.Prepare, - []bls.SerializedPublicKey{validatorKey}, + []*bls.PublicKeyWrapper{&validatorKeyWrapper}, validatorPriKey.Sign(message), common.BytesToHash(consensus.blockHash[:]), consensus.blockNum, diff --git a/consensus/quorum/one-node-one-vote.go b/consensus/quorum/one-node-one-vote.go index 45db9bcd3..7455d6e72 100644 --- a/consensus/quorum/one-node-one-vote.go +++ b/consensus/quorum/one-node-one-vote.go @@ -36,7 +36,7 @@ func (v *uniformVoteWeight) AddNewVote( for i, pubKey := range pubKeys { pubKeysBytes[i] = pubKey.Bytes } - return v.SubmitVote(p, pubKeysBytes, sig, headerHash, height, viewID) + return v.submitVote(p, pubKeysBytes, sig, headerHash, height, viewID) } // IsQuorumAchieved .. diff --git a/consensus/quorum/one-node-staked-vote.go b/consensus/quorum/one-node-staked-vote.go index 8023b03d8..0f65257c9 100644 --- a/consensus/quorum/one-node-staked-vote.go +++ b/consensus/quorum/one-node-staked-vote.go @@ -82,7 +82,7 @@ func (v *stakedVoteWeight) AddNewVote( pubKeysBytes[i] = pubKey.Bytes } - ballet, err := v.SubmitVote(p, pubKeysBytes, sig, headerHash, height, viewID) + ballet, err := v.submitVote(p, pubKeysBytes, sig, headerHash, height, viewID) if err != nil { return ballet, err diff --git a/consensus/quorum/quorom_test.go b/consensus/quorum/quorom_test.go index d6b91a5bf..73767ea25 100644 --- a/consensus/quorum/quorom_test.go +++ b/consensus/quorum/quorom_test.go @@ -88,7 +88,7 @@ func TestSubmitVote(test *testing.T) { decider.UpdateParticipants([]bls.PublicKeyWrapper{pubKeyWrapper1, pubKeyWrapper2}) - if _, err := decider.SubmitVote( + if _, err := decider.submitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper1.Bytes}, blsPriKey1.Sign(message), @@ -99,7 +99,7 @@ func TestSubmitVote(test *testing.T) { test.Log(err) } - if _, err := decider.SubmitVote( + if _, err := decider.submitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes}, blsPriKey2.Sign(message), @@ -110,7 +110,7 @@ func TestSubmitVote(test *testing.T) { test.Log(err) } if decider.SignersCount(Prepare) != 2 { - test.Fatal("SubmitVote failed") + test.Fatal("submitVote failed") } aggSig := &bls_core.Sign{} @@ -145,7 +145,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { decider.UpdateParticipants([]bls.PublicKeyWrapper{pubKeyWrapper1, pubKeyWrapper2}) - decider.SubmitVote( + decider.submitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper1.Bytes}, blsPriKey1.SignHash(blockHash[:]), @@ -160,7 +160,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { aggSig.Add(s) } } - if _, err := decider.SubmitVote( + if _, err := decider.submitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes, pubKeyWrapper3.Bytes}, aggSig, @@ -172,7 +172,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { } if decider.SignersCount(Prepare) != 3 { - test.Fatal("SubmitVote failed") + test.Fatal("submitVote failed") } aggSig.Add(blsPriKey1.SignHash(blockHash[:])) @@ -180,7 +180,7 @@ func TestSubmitVoteAggregateSig(test *testing.T) { test.Fatal("AggregateVotes failed") } - if _, err := decider.SubmitVote( + if _, err := decider.submitVote( Prepare, []bls.SerializedPublicKey{pubKeyWrapper2.Bytes}, aggSig, diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index f41d47ec1..ed5556614 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -81,7 +81,8 @@ type ParticipantTracker interface { // SignatoryTracker .. type SignatoryTracker interface { ParticipantTracker - SubmitVote( + // This func shouldn't be called directly from outside of quorum. Use AddNewVote instead. + submitVote( p Phase, pubkeys []bls.SerializedPublicKey, sig *bls_core.Sign, headerHash common.Hash, height, viewID uint64, From a7ebc10ef54bb78ce0fa5982dc857b93010f520f Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 2 Nov 2020 21:53:49 -0800 Subject: [PATCH 4/6] fix build --- consensus/quorum/quorum.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/quorum/quorum.go b/consensus/quorum/quorum.go index ed5556614..823c2a7f0 100644 --- a/consensus/quorum/quorum.go +++ b/consensus/quorum/quorum.go @@ -274,7 +274,7 @@ func (s *cIdentities) SignersCount(p Phase) int64 { } } -func (s *cIdentities) SubmitVote( +func (s *cIdentities) submitVote( p Phase, pubkeys []bls.SerializedPublicKey, sig *bls_core.Sign, headerHash common.Hash, height, viewID uint64, From fea096b0f97152ca195b50dd4d0a31b46d5311f6 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 2 Nov 2020 22:13:05 -0800 Subject: [PATCH 5/6] Fix view id calc --- consensus/view_change.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/consensus/view_change.go b/consensus/view_change.go index 37df69712..3ef66eb9d 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -131,9 +131,8 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) { if curTimestamp <= blockTimestamp { return consensus.fallbackNextViewID() } - totalNode := consensus.Decider.ParticipantsCount() - // diff is at least 1, and it won't exceed the totalNode - diff := uint64(((curTimestamp - blockTimestamp) / viewChangeTimeout) % int64(totalNode)) + // diff only increases + diff := uint64((curTimestamp - blockTimestamp) / viewChangeTimeout) nextViewID := diff + consensus.GetCurBlockViewID() consensus.getLogger().Info(). From e165c4d55c5bd9897c233b6770a70d183ba5ee70 Mon Sep 17 00:00:00 2001 From: Daniel Van Der Maden Date: Tue, 3 Nov 2020 11:34:31 -0800 Subject: [PATCH 6/6] [rosetta] Support EVM pre-process for contract creation txs (#3424) * [rosetta] Support EVM pre-process for contract creation txs Signed-off-by: Daniel Van Der Maden * [rosetta] Fix re-delegation amount Signed-off-by: Daniel Van Der Maden --- rosetta/services/construction_check.go | 9 +++++---- rosetta/services/tx_operation.go | 14 +++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/rosetta/services/construction_check.go b/rosetta/services/construction_check.go index 53d1b5f2a..e38eb6a36 100644 --- a/rosetta/services/construction_check.go +++ b/rosetta/services/construction_check.go @@ -240,16 +240,17 @@ func (s *ConstructAPI) ConstructionMetadata( evmErrorMsg := "" evmReturn := hexutil.Bytes{} - if !isStakingOperation(options.OperationType) && - options.OperationType != common.ContractCreationOperation && - len(data) > 0 { + if len(data) > 0 && (options.OperationType == common.ContractCreationOperation || + options.OperationType == common.NativeTransferOperation) { gas := hexutil.Uint64(estGasUsed) callArgs := rpc.CallArgs{ From: senderAddr, - To: &contractAddress, Data: &data, Gas: &gas, } + if options.OperationType == common.NativeTransferOperation { + callArgs.To = &contractAddress + } evmExe, err := rpc.DoEVMCall( ctx, s.hmy, callArgs, ethRpc.LatestBlockNumber, vm.Config{}, rpc.CallTimeout, s.hmy.RPCGasCap, ) diff --git a/rosetta/services/tx_operation.go b/rosetta/services/tx_operation.go index 682e6645c..8d7f4a28b 100644 --- a/rosetta/services/tx_operation.go +++ b/rosetta/services/tx_operation.go @@ -158,20 +158,16 @@ func getAmountFromDelegateMessage(receipt *hmytypes.Receipt, data []byte) (*type }) } - stkAmount := stkMsg.Amount + deductedAmt := stkMsg.Amount logs := hmytypes.FindLogsWithTopic(receipt, staking.DelegateTopic) for _, log := range logs { - if len(log.Data) > ethcommon.AddressLength { - validatorAddress := ethcommon.BytesToAddress(log.Data[:ethcommon.AddressLength]) - if log.Address == stkMsg.DelegatorAddress && stkMsg.ValidatorAddress == validatorAddress { - // Remove re-delegation amount as funds were never credited to account's balance. - stkAmount = new(big.Int).Sub(stkAmount, new(big.Int).SetBytes(log.Data[ethcommon.AddressLength:])) - break - } + if len(log.Data) > ethcommon.AddressLength && log.Address == stkMsg.DelegatorAddress { + // Remove re-delegation amount as funds were never credited to account's balance. + deductedAmt = new(big.Int).Sub(deductedAmt, new(big.Int).SetBytes(log.Data[ethcommon.AddressLength:])) } } return &types.Amount{ - Value: negativeBigValue(stkAmount), + Value: negativeBigValue(deductedAmt), Currency: &common.NativeCurrency, }, nil }