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

Commit parent finality #193

Merged
merged 37 commits into from
Sep 13, 2023
Merged

Commit parent finality #193

merged 37 commits into from
Sep 13, 2023

Conversation

cryptoAtwill
Copy link
Collaborator

@cryptoAtwill cryptoAtwill commented Aug 29, 2023

Initial attempt to store and retrieve IPC parent finality in gateway contract. The updates are as follows:

  • Move setMembership to GatewayLib and remove the corresponding external function call in GatewayManagerFacet.
  • Add commitParentFinality to RouterFacet.
  • Add queryParentFinality to GatewayGetterFacet.

In follow up PR will clean up the code by removing submit top down and bottom up checkpoint and all their internal functions.

@cryptoAtwill cryptoAtwill marked this pull request as draft August 29, 2023 00:07
@adlrocha adlrocha self-requested a review August 29, 2023 06:55
@cryptoAtwill cryptoAtwill changed the title initial commit Commit parent finality Aug 30, 2023
test/GatewayDiamond.t.sol Outdated Show resolved Hide resolved
test/GatewayDiamond.t.sol Outdated Show resolved Hide resolved
src/gateway/GatewayRouterFacet.sol Show resolved Hide resolved
src/gateway/GatewayGetterFacet.sol Show resolved Hide resolved
@cryptoAtwill cryptoAtwill marked this pull request as ready for review August 31, 2023 04:51
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.

LGTM. The reason I request the change is because to wrap it up we should remove

function initGenesisEpoch(uint64 genesisEpoch) external systemActorOnly {
. I don't think is needed anymore. If we need the topDownGenesisEpoch for something, we can set it directly when the first proof of finality is committed, but it can be kind of a mess having to also call this initGenesisEpoch implicitly when we are actually doing it implicitly when committing finality.

We can discuss sync if it is not clear.

test/GatewayDiamond.t.sol Outdated Show resolved Hide resolved
src/lib/LibGateway.sol Show resolved Hide resolved
revert ValidatorWeightIsZero();
}

s.validatorSet[s.validatorNonce][validatorAddress] = validatorWeight;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to address it immediately, but we will need to garbage collect the membership info instead of keeping all the history. We may be able to garbage collect outdated info.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added another variable to track the block height of the last committed height, we can commit and delete at the same time. I can implement this logic in follow up PRs.

src/lib/LibGatewayActorStorage.sol Outdated Show resolved Hide resolved
@adlrocha
Copy link
Contributor

@cryptoAtwill, we should also remove all the code around TopDownVoting, _submitTopDownVote, etc. This is no longer necessary. I'll check the changes required to apply_messages and we can discuss if to apply them here or in some other PR.

@cryptoAtwill
Copy link
Collaborator Author

@adlrocha sounds good, I will do all those deletion related work in a PR on top of this so that the changes are not mixed in this PR.

@cryptoAtwill
Copy link
Collaborator Author

@adlrocha I will create a separate PR to delete other methods, such as initGenesis. Because keep on deleting them will fail the unit tests and the PR get bigger. Another PR might be neater.

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.

@cryptoAtwill, few more changes before we merge, I can address them myself if you want. Let me know.

src/gateway/GatewayMessengerFacet.sol Show resolved Hide resolved
src/gateway/GatewayRouterFacet.sol Show resolved Hide resolved
/// This functions verifies that the checkpoint is valid before
/// propagating it for commitment to the IPC gateway. It expects at least
/// votes from 2/3 of miners with collateral.
function submitCheckpoint(BottomUpCheckpoint calldata checkpoint) external;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should remove submitCheckpoint. It will change a lot, but will still be necessary with the new design (can you revert this one)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added back

@@ -104,52 +104,6 @@ contract SubnetActorManagerFacet is ISubnetActor, SubnetActorModifiers, Reentran
IGateway(s.ipcGatewayAddr).kill();
}

/// @notice methods that allows a validator to submit a checkpoint (batch of messages) and vote for it with it's own voting power.
/// @param checkpoint - the batch messages data
function submitCheckpoint(BottomUpCheckpoint calldata checkpoint) external {
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't remove this one for the same of above, bottom up checkpoints will be re-designed (without votings) but we still need it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added back

using StorableMsgHelper for StorableMsg;

/// @notice submit a checkpoint in the gateway. Called from a subnet once the checkpoint is voted for and reaches majority
function commitChildCheck(BottomUpCheckpoint calldata commit) external {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also keep this one in the gateway.


subnet.prevCheckpoint = commit;
/// @notice commit the ipc parent finality into storage
function commitParentFinality(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this method not in the GatewayActor interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this into the interface already


subnet.prevCheckpoint = commit;
/// @notice commit the ipc parent finality into storage
function commitParentFinality(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you provide more information about that function? What is the relation between finality data and validators and why are these validators added to membership?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, I think this is the mechanism of the top down checkpointing in fendermint, not sure if it suitable to place the docs here.

But long story short, membership information is pulled from the parent ipc-agent or node in fendermint. Then fendermint call this function implicitly.

@@ -15,6 +15,10 @@ struct GatewayActorStorage {
/// @notice a mapping of block number to cross messages
/// SubnetID => blockNumber => messages
mapping(bytes32 => mapping(uint256 => CrossMsg[])) topDownMsgs;
/// @notice The parent finalities. Key is the block number, value is the finality struct.
mapping(uint256 => ParentFinality) finalitiesMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it that fine we do not have a relation between committed ParentFinality and validators that committed it? Do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really. We just need the block height to parent finality.


subnet.prevCheckpoint = commit;
/// @notice commit the ipc parent finality into storage
function commitParentFinality(
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the proof (multisig) that this was committed by these validators?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For top down parent finality, we dont really need mutisig.

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.

Thank you for the changes, 🚢

@cryptoAtwill cryptoAtwill merged commit 34f3bf6 into dev Sep 13, 2023
5 checks passed
@cryptoAtwill cryptoAtwill deleted the topdown-finality branch September 13, 2023 06:22
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.

3 participants