Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem: (Fix #1435) No standardized staking event #1449

Merged
merged 1 commit into from
Apr 22, 2020

Conversation

calvinlauyh
Copy link
Contributor

@calvinlauyh calvinlauyh commented Apr 18, 2020

Solution: Refactor staking related events to standardized events


  • Remove RewardsDistribution and SlashValidators event
  • Standardized all staking address related actions into StakingChange event
  • Some sample event format (base64 encoded values are decoded)

Transaction

{
    type: 'StakingChange',
    attributes: [
        {
            key: 'staking_address',
            value: '0x2dfde2178daa679508828242119dcf2114038ea8',
        },
        {
            key: 'staking_optype',
            value: 'unbond',
        },
        {
            key: 'staking_diff',
            value: '[{key:'Bonded',value:"-1000"},{key:"Unbonded",value:"1000"}]'
        }
    ]
}

BeginBlock

{
  "begin_block": {
    "events": [
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "MHgyZGZkZTIxNzhkYWE2Nzk1MDg4MjgyNDIxMTlkY2YyMTE0MDM4ZWE4"
          },
          {
            "key": "staking_optype",
            "value": "slash"
          },
          {
            "key": "staking_diff",
            "value": "[{\"key\":\"Bonded\",\"value\":\"-50000000000\"},{\"key\":\"Unbonded\",\"value\":\"-50000000000\"}]"
          },
          {
            "key": "staking_opreason",
            "value": "NonLive"
          }
        ]
      },
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "0x45c1851c2f0dc6138935857b9e23b173185fea15"
          },
          {
            "key": "staking_optype",
            "value": "reward"
          },
          {
            "key": "staking_diff",
            "value": "{\"key\":\"Bonded\",\"value\":\"100000000000\"}"
          }
        ]
      },
      {
        "type": "reward",
        "attributes": [
          {
            "key": "minted",
            "value": "\"0\""
          }
        ]
      }
    ]
  }
}

@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch from 3e2c556 to 6d5fa72 Compare April 18, 2020 11:01
@calvinaco calvinaco requested review from yihuang and lezzokafka April 18, 2020 11:02
@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch 2 times, most recently from 616f316 to bd5fab0 Compare April 18, 2020 13:39
@codecov
Copy link

codecov bot commented Apr 18, 2020

Codecov Report

Merging #1449 into master will increase coverage by 0.89%.
The diff coverage is 96.82%.

@@            Coverage Diff             @@
##           master    #1449      +/-   ##
==========================================
+ Coverage   63.55%   64.44%   +0.89%     
==========================================
  Files         159      160       +1     
  Lines       21026    21632     +606     
==========================================
+ Hits        13363    13941     +578     
- Misses       7663     7691      +28     
Impacted Files Coverage Δ
chain-core/src/init/coin.rs 84.21% <ø> (-2.20%) ⬇️
chain-core/src/common/mod.rs 68.88% <70.00%> (-2.54%) ⬇️
chain-abci/src/storage/mod.rs 84.61% <76.08%> (-3.25%) ⬇️
chain-abci/src/app/validate_tx.rs 81.42% <91.66%> (-1.68%) ⬇️
chain-abci/src/app/mod.rs 83.01% <96.05%> (+0.20%) ⬆️
...lient-common/src/tendermint/types/block_results.rs 90.09% <96.29%> (-0.82%) ⬇️
chain-abci/src/staking/mod.rs 99.10% <96.55%> (-0.66%) ⬇️
chain-abci/src/app/staking_event.rs 99.38% <99.38%> (ø)
chain-abci/src/staking/table.rs 89.07% <100.00%> (+0.51%) ⬆️
chain-abci/src/staking/tx.rs 91.89% <100.00%> (+0.07%) ⬆️
... and 10 more

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

looks ok, but agree with #1449 (comment) -- processing that only needs TxEnclaveAction should only get TxEnclaveAction as input;
processing that needs both can have that top-level TxAction

}
_ => panic!("Trying to execute non-enclave transaction"),
Copy link
Contributor

Choose a reason for hiding this comment

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

this "catch-all" is potentially error-prone if a new enclave tx variant is added and it's not handled here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code updated based on review

@yihuang
Copy link
Collaborator

yihuang commented Apr 20, 2020

          {
            "key": "staking_diff",
            "value": "{\"key\":\"Bonded\",\"value\":\"-50000000000\"}"
          },
          {
            "key": "staking_diff",
            "value": "{\"key\":\"Unbonded\",\"value\":\"-50000000000\"}"
          },

How about merge them into one item:

          {
            "key": "staking_diff",
            "value": "[[\"Unbonded\", \"-50000000000\"], [\"Bonded\", \"-50000000000\"]]"
          }

@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch from bd5fab0 to 7f810cb Compare April 20, 2020 08:49
@calvinlauyh
Copy link
Contributor Author

bors try

@bors
Copy link
Contributor

bors bot commented Apr 20, 2020

🔒 Permission denied

Existing reviewers: click here to make calvinlauco a reviewer

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

looks ok, there may be some minor improvemensts to do down the line

Comment on lines 174 to 178
StakedStateAddress,
Coin,
Coin,
PunishmentKind,
Option<Timespec>,
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be good to have some type alias for this -- also what's difference between the Coin on the second position and the third position

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an alias PunishmentKind and refactored the (Coin, Coin) pair to SlashedCoin structure for readability.

@tomtau
Copy link
Contributor

tomtau commented Apr 21, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 21, 2020

Merge conflict.

@tomtau tomtau self-requested a review April 21, 2020 06:25
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

there's a conflict with the latest master

@calvinlauyh
Copy link
Contributor Author

there's a conflict with the latest master

Resolving conflicts now

@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch 2 times, most recently from 1674b60 to 3065b4d Compare April 21, 2020 10:50
@calvinlauyh
Copy link
Contributor Author

Conflicts resolved

@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch from 3065b4d to eda30e3 Compare April 21, 2020 11:09
@calvinaco
Copy link
Collaborator

bors try

bors bot added a commit that referenced this pull request Apr 21, 2020
@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch from eda30e3 to 391e90d Compare April 21, 2020 11:54
@calvinlauyh
Copy link
Contributor Author

Updated based on TravisCI lint suggestion.

@bors
Copy link
Contributor

bors bot commented Apr 21, 2020

try

Build failed:

@calvinaco
Copy link
Collaborator

bors try

bors bot added a commit that referenced this pull request Apr 21, 2020
@bors
Copy link
Contributor

bors bot commented Apr 21, 2020

try

Build succeeded:

@tomtau
Copy link
Contributor

tomtau commented Apr 22, 2020

bors r+

bors bot added a commit that referenced this pull request Apr 22, 2020
1449: Problem: (Fix #1435) No standardized staking event r=tomtau a=calvinlauco

Solution: Refactor staking related events to standardized events

---

- Remove `RewardsDistribution` and `SlashValidators ` event
- Standardized all staking address related actions into `StakingChange` event
- Some sample event format (base64 encoded values are decoded)

#### Transaction
```
{
    type: 'StakingChange',
    attributes: [
        {
            key: 'staking_address',
            value: '0x2dfde2178daa679508828242119dcf2114038ea8',
        },
        {
            key: 'staking_optype',
            value: 'unbond',
        },
        {
            key: 'staking_diff',
            value: '[{key:'Bonded',value:"-1000"},{key:"Unbonded",value:"1000"}]'
        }
    ]
}
```

#### BeginBlock
```
{
  "begin_block": {
    "events": [
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "MHgyZGZkZTIxNzhkYWE2Nzk1MDg4MjgyNDIxMTlkY2YyMTE0MDM4ZWE4"
          },
          {
            "key": "staking_optype",
            "value": "slash"
          },
          {
            "key": "staking_diff",
            "value": "[{\"key\":\"Bonded\",\"value\":\"-50000000000\"},{\"key\":\"Unbonded\",\"value\":\"-50000000000\"}]"
          },
          {
            "key": "staking_opreason",
            "value": "NonLive"
          }
        ]
      },
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "0x45c1851c2f0dc6138935857b9e23b173185fea15"
          },
          {
            "key": "staking_optype",
            "value": "reward"
          },
          {
            "key": "staking_diff",
            "value": "{\"key\":\"Bonded\",\"value\":\"100000000000\"}"
          }
        ]
      },
      {
        "type": "reward",
        "attributes": [
          {
            "key": "minted",
            "value": "\"0\""
          }
        ]
      }
    ]
  }
}

```

Co-authored-by: Calvin Lau <[email protected]>
@tomtau
Copy link
Contributor

tomtau commented Apr 22, 2020

bors r-

@bors
Copy link
Contributor

bors bot commented Apr 22, 2020

Canceled.

@calvinlauyh
Copy link
Contributor Author

Updated to add missing unbonded_from to event

@calvinaco
Copy link
Collaborator

bors try

bors bot added a commit that referenced this pull request Apr 22, 2020
@tomtau
Copy link
Contributor

tomtau commented Apr 22, 2020

bors r+

bors bot added a commit that referenced this pull request Apr 22, 2020
1449: Problem: (Fix #1435) No standardized staking event r=tomtau a=calvinlauco

Solution: Refactor staking related events to standardized events

---

- Remove `RewardsDistribution` and `SlashValidators ` event
- Standardized all staking address related actions into `StakingChange` event
- Some sample event format (base64 encoded values are decoded)

#### Transaction
```
{
    type: 'StakingChange',
    attributes: [
        {
            key: 'staking_address',
            value: '0x2dfde2178daa679508828242119dcf2114038ea8',
        },
        {
            key: 'staking_optype',
            value: 'unbond',
        },
        {
            key: 'staking_diff',
            value: '[{key:'Bonded',value:"-1000"},{key:"Unbonded",value:"1000"}]'
        }
    ]
}
```

#### BeginBlock
```
{
  "begin_block": {
    "events": [
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "MHgyZGZkZTIxNzhkYWE2Nzk1MDg4MjgyNDIxMTlkY2YyMTE0MDM4ZWE4"
          },
          {
            "key": "staking_optype",
            "value": "slash"
          },
          {
            "key": "staking_diff",
            "value": "[{\"key\":\"Bonded\",\"value\":\"-50000000000\"},{\"key\":\"Unbonded\",\"value\":\"-50000000000\"}]"
          },
          {
            "key": "staking_opreason",
            "value": "NonLive"
          }
        ]
      },
      {
        "type": "staking_change",
        "attributes": [
          {
            "key": "staking_address",
            "value": "0x45c1851c2f0dc6138935857b9e23b173185fea15"
          },
          {
            "key": "staking_optype",
            "value": "reward"
          },
          {
            "key": "staking_diff",
            "value": "{\"key\":\"Bonded\",\"value\":\"100000000000\"}"
          }
        ]
      },
      {
        "type": "reward",
        "attributes": [
          {
            "key": "minted",
            "value": "\"0\""
          }
        ]
      }
    ]
  }
}

```

Co-authored-by: Calvin Lau <[email protected]>
Solution: Refactor staking related events to standardized events
@calvinlauyh calvinlauyh force-pushed the feature/1435-staking-event branch from 5325938 to bacdb1b Compare April 22, 2020 03:31
@bors
Copy link
Contributor

bors bot commented Apr 22, 2020

Canceled.

@calvinlauyh
Copy link
Contributor Author

bors r+

@tomtau
Fixed formatting issue found on TravisCI.

@devashishdxt
Copy link
Collaborator

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 22, 2020

try

Build failed:

@calvinlauyh
Copy link
Contributor Author

try

Build failed:

This error comes from last bors try attempt before the format fix. Can be ignored

Copy link
Collaborator

@leejw51crypto leejw51crypto left a comment

Choose a reason for hiding this comment

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

lgtm

@bors
Copy link
Contributor

bors bot commented Apr 22, 2020

Build succeeded:

@bors bors bot merged commit b4a0b29 into crypto-com:master Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants