Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Test staking: Part 2 #319

Merged
merged 49 commits into from
Oct 25, 2023
Merged

Test staking: Part 2 #319

merged 49 commits into from
Oct 25, 2023

Conversation

aakoshh
Copy link
Contributor

@aakoshh aakoshh commented Oct 18, 2023

Continuation of #299

  • apply update immediately until activated
  • activate on collateral reached
  • join and leave command
  • implement join and leave on the model state
  • implement unstake in the contract
  • call the SUT for join
  • call the SUT for stake
  • call the SUT for leave
  • call the SUT for unstake
  • call the SUT for checkpoint
  • validate balances
  • validate stakes
  • validate top N validators
  • generate a non-empty cross message vector to check hashing

Fixes:

Running

The tests can be executed as follows:

cargo test --release -p contract-test --test smt_staking 

To run them on modified Solidity contracts, change the Cargo.toml file like so:

[patch."https://github.com/consensus-shipyard/ipc-solidity-actors.git"]
ipc_actors_abis = { path = "../ipc-solidity-actors/binding" }

And then run make ipc-actors-abi to recompile the ABI artifacts.

Notes

Ranking

I cannot replicate the exact ordering of validators when multiple validators have the same collateral, which can lead to disagreements between Rust and Solidity about who exactly are the top N validators, when validator N and N+1 both have the same collateral.

I used a stable sorting mechanism hoping that it will work fairly: given a sorted list of validators, we update the collateral, and the move them up or down to their new place, leaving others in place.

However, in Solidity the priority queues are unstable. For example:

  • Say we we have the following values in a min-heap: [1a, 2b, 2c, 3d, 3e, 3f], where the letter is the validator identity and the number is their collateral
  • Say we want to pop/delete the minimum value 1a
  • The algorithm first swaps 1a with the last element 3f, resulting in [3f, 2b, 2c, 3d, 3e, 1a]. Then it removes the last element and makes the queue shorter. Finally it sinks the first element back into its place, resulting in [2b, 2c, 3f, 3d, 3e].
  • So 3f moved from being the last to the top of the "threes".
  • By contrast, in Rust we just remove 1a from the queue if it leaves, leaving the others in their relative order.

If this situation arises, I stop testing the system further and start with a fresh state. I don't think it's worth trying to replicate this exact ordering mechanism.

Copy link
Contributor

@adlrocha adlrocha left a comment

Choose a reason for hiding this comment

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

These tests are actual gold, @aakoshh. Thanks! This makes testing significantly easier than what we were doing pre-Fendermint ❤️

) -> TryCallResult<()> {
let public_key = validator.public_key.0.serialize();
let addr = EthAddress::new_secp256k1(&public_key)?;
let deposit = from_fvm::to_eth_tokens(&validator.power.0)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this from_fvm and from_eth conversion utils. I feel we should expose them as a crate and make them available to the ipc repo. I feel we have a lot of redundant conversion functions here and there :)

//cc @cryptoAtwill, thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are exposed in the messages crate, but some low level ones might be useful on their own for someone who doesn't want to deal with Fendermint message types.

fendermint/testing/contract-test/tests/staking/machine.rs Outdated Show resolved Hide resolved
fendermint/testing/contract-test/tests/staking/machine.rs Outdated Show resolved Hide resolved
@aakoshh aakoshh marked this pull request as ready for review October 24, 2023 13:09
@aakoshh aakoshh merged commit 66ca42d into main Oct 25, 2023
1 check passed
@aakoshh aakoshh deleted the test-staking-part-2 branch October 25, 2023 07:34
cryptoAtwill added a commit that referenced this pull request Oct 25, 2023
* fix lotus querying

* query range

* fix decoding

* Revert typechain

* log of parsing

* fix order

* more logs

* more logs

* more logs

* disable change set

* debug

* more code

* more code

* more code

* more logs

* mint to gateway

* debug code

* working version with clean up

* update comments

* remove testing code

* fix lint

* adding topdown module

* remove unused code

* Test staking: Part 2 (#319)

* TEST: Use EthAddress

* TEST: Update closure

* TEST: Generate join and leave

* TEST: Separate configuration number for current and next

* TEST: Take &mut self in StakingState

* TEST: Test join

* TEST: Test collateral and balance

* TEST: Test stake command; fix check of has_joined

* TEST: Test leave command; fix total collateral

* TEST: Test checkpoint command; signature fails

* TEST: Build checkpoint during command run

* TEST: Higher default random size

* TEST: Unit test for ABI encoding

* TEST: Hash checkpoint as tuple

* TEST: Try sending the signature with +27 recovery ID

* TEST: Use non-masked ethereum address

* TEST: Do not increment config when staking 0

* TEST: Tweak token amount generation so there aren't that many zeroes

* TEST: Choose min_collateral so the last joiner activates

* TEST: Bootstrap tests

* TEST: Claim

* TEST: Show error data in genesis

* TEST: min_collateral > 0

* TEST: use local actors

* TEST: Ranking

* TEST: Subnet deactivation

* TEST: Trying to debug the active validator set

* TEST: See doesn't need bytes

* TEST: Do not fail test if minimum collateral disagrees

* TEST: Maybe we should fail

* TEST: Assert active limit

* TEST: Fix repeatability

* TEST: Example of going over the limit of 2 active validators

* TEST: Debugged the over-the-limit validators

* TEST: Fix the active collateral sum

* TEST: Quit testing if we hit the situation of differently ordered minimum collaterals

* TEST: Check the hash of cross messages

* TEST: Point at the integration testing branch of ABIs

* TEST: Fix clippy

* TEST: Update ABI git reference

* FIX: Only take the /out

* FIX: Install openssl in docker

* TEST: Update Rust version in docker

* FIX: Remove debug

* FIX: 27 shift only needed by Solidity

* TEST: Add unstake

* FIX: SMT unit tests

* FIX: Update RocksDB code

* TEST: Use IPC actors dev

* Update fendermint/vm/interpreter/src/fvm/state/ipc.rs

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>

* update cargo

* format code

* log parent sync messages

* sort staking change requests

* sort in ascending order

* fmt code

---------

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>
cryptoAtwill added a commit that referenced this pull request Oct 25, 2023
* migrate top down crate

* top down crate

* new ipc changes

* export proxy mod

* fix tests

* update cargo

* update convert

* stashed

* stashed

* initial impl

* update cargo

* lint

* update tests

* execute top down

* format code

* fm-303: update ipc sdk deps

* ipc-308: address review

* ipc-308: add additional check for reorgs

* ipc-308: revert additional reorg check and add todo

* detect chain reorg

* temp changes

* update reorg

* fix tests

* fix review

* move get finality

* more logging

* fix getting genesis epoch

* update config

* more logging

* more logs

* update cargo lock

* update config

* remove network name

* more logs

* update cargo

* fix top down error

* more logs

* fix prev hash

* revert toolchain

* implicit execution

* remove context

* implicit execution

* more logging

* more logging

* address review

* Fix topdown (#321)

* fix lotus querying

* query range

* fix decoding

* Revert typechain

* log of parsing

* fix order

* more logs

* more logs

* more logs

* disable change set

* debug

* more code

* more code

* more code

* more logs

* mint to gateway

* debug code

* working version with clean up

* update comments

* remove testing code

* fix lint

* adding topdown module

* remove unused code

* Test staking: Part 2 (#319)

* TEST: Use EthAddress

* TEST: Update closure

* TEST: Generate join and leave

* TEST: Separate configuration number for current and next

* TEST: Take &mut self in StakingState

* TEST: Test join

* TEST: Test collateral and balance

* TEST: Test stake command; fix check of has_joined

* TEST: Test leave command; fix total collateral

* TEST: Test checkpoint command; signature fails

* TEST: Build checkpoint during command run

* TEST: Higher default random size

* TEST: Unit test for ABI encoding

* TEST: Hash checkpoint as tuple

* TEST: Try sending the signature with +27 recovery ID

* TEST: Use non-masked ethereum address

* TEST: Do not increment config when staking 0

* TEST: Tweak token amount generation so there aren't that many zeroes

* TEST: Choose min_collateral so the last joiner activates

* TEST: Bootstrap tests

* TEST: Claim

* TEST: Show error data in genesis

* TEST: min_collateral > 0

* TEST: use local actors

* TEST: Ranking

* TEST: Subnet deactivation

* TEST: Trying to debug the active validator set

* TEST: See doesn't need bytes

* TEST: Do not fail test if minimum collateral disagrees

* TEST: Maybe we should fail

* TEST: Assert active limit

* TEST: Fix repeatability

* TEST: Example of going over the limit of 2 active validators

* TEST: Debugged the over-the-limit validators

* TEST: Fix the active collateral sum

* TEST: Quit testing if we hit the situation of differently ordered minimum collaterals

* TEST: Check the hash of cross messages

* TEST: Point at the integration testing branch of ABIs

* TEST: Fix clippy

* TEST: Update ABI git reference

* FIX: Only take the /out

* FIX: Install openssl in docker

* TEST: Update Rust version in docker

* FIX: Remove debug

* FIX: 27 shift only needed by Solidity

* TEST: Add unstake

* FIX: SMT unit tests

* FIX: Update RocksDB code

* TEST: Use IPC actors dev

* Update fendermint/vm/interpreter/src/fvm/state/ipc.rs

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>

* update cargo

* format code

* log parent sync messages

* sort staking change requests

* sort in ascending order

* fmt code

---------

Co-authored-by: Akosh Farkash <aakoshh@gmail.com>

---------

Signed-off-by: Alfonso de la Rocha <adlrocha@tutamail.com>
Co-authored-by: Alfonso de la Rocha <adlrocha@tutamail.com>
Co-authored-by: Akosh Farkash <aakoshh@gmail.com>
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.

2 participants