Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-log-message-double-stake #2540

Merged
merged 4 commits into from Dec 4, 2020
Merged

Conversation

sasurobert
Copy link
Contributor

fix log message. added protection against staking same key two times in the same stake call.

@@ -178,7 +179,9 @@ func (stp *stakingToPeer) UpdateProtocol(body *block.Body, nonce uint64) error {
// no data under key -> peer can be deleted from trie
if len(data) == 0 {
err = stp.peerState.RemoveAccount(blsPubKey)
log.LogIfError(err, "staking to protocol RemoveAccount blsPubKey", blsPubKey)
if err != nil {
log.Debug("staking to protocol RemoveAccount", "error", err, "blsPubKey", hex.EncodeToString(blsPubKey))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use stp.pubkeyConv.Encode instead of hex.EncodeToString(blsPubKey)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is bls key, not bech32.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pubkeyConv is of type hexPkConverter. Can be left as it is

func checkDoubleBLSKeys(blsKeys [][]byte) bool {
mapKeys := make(map[string]struct{})
for _, blsKey := range blsKeys {
_, found := mapKeys[string(blsKey)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

vm/systemSmartContracts/auction.go Outdated Show resolved Hide resolved
@@ -178,7 +179,9 @@ func (stp *stakingToPeer) UpdateProtocol(body *block.Body, nonce uint64) error {
// no data under key -> peer can be deleted from trie
if len(data) == 0 {
err = stp.peerState.RemoveAccount(blsPubKey)
log.LogIfError(err, "staking to protocol RemoveAccount blsPubKey", blsPubKey)
if err != nil {
log.Debug("staking to protocol RemoveAccount", "error", err, "blsPubKey", hex.EncodeToString(blsPubKey))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staking to peer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all logs here are with staking to protocol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -776,6 +792,11 @@ func (s *stakingAuctionSC) stake(args *vmcommon.ContractCallInput) vmcommon.Retu
return vmcommon.UserError
}

if s.flagDoubleKey.IsSet() && checkDoubleBLSKeys(blsKeys) {
s.eei.AddReturnMessage("invalid arguments, found same bls key twice")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more than ones/many times ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it stops at found twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

iulianpascalau
iulianpascalau previously approved these changes Dec 2, 2020
SebastianMarian
SebastianMarian previously approved these changes Dec 2, 2020
iulianpascalau
iulianpascalau previously approved these changes Dec 3, 2020
newList := make([][]byte, 0)
mapExistingKeys := make(map[string]struct{})
for _, blsKey := range registrationData.BlsPubKeys {
if _, found := mapExistingKeys[string(blsKey)]; found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return vmcommon.UserError
}

err := s.eei.UseGas(s.gasCost.MetaChainSystemSCsCost.Stake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the cost for cleaning is s.gasCost.MetaChainSystemSCsCost.Stake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

return vmcommon.UserError
}

if len(registrationData.BlsPubKeys) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be <= 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

mapExistingKeys[string(blsKey)] = struct{}{}
newList = append(newList, blsKey)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add here:

if !changesMade {
   return vmcommon.Ok
}

To avoid useless make and set with the same content, and remove L775 and L781

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@stefanandy stefanandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System Test Passed

@iulianpascalau iulianpascalau merged commit 9427c1b into master Dec 4, 2020
@LucianMincu LucianMincu deleted the fix-log-message-double-stake branch December 29, 2020 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants