Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Mar 1, 2023
1 parent e1035e3 commit c7409e4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
9 changes: 2 additions & 7 deletions core/packages/contracts/contracts/BeefyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,7 @@ contract BeefyClient is Ownable {
revert StaleCommitment();
}

if (
leaf.nextAuthoritySetID != nextValidatorSet.id &&
leaf.nextAuthoritySetID != nextValidatorSet.id + 1
) {
if (leaf.nextAuthoritySetID != nextValidatorSet.id + 1) {
revert InvalidMMRLeaf();
}

Expand All @@ -353,9 +350,7 @@ contract BeefyClient is Ownable {
}

currentValidatorSet = nextValidatorSet;
// Workaround for change in https://github.com/paritytech/polkadot/pull/6577
// and discussions here in https://github.com/paritytech/substrate/issues/11797
nextValidatorSet.id = currentValidatorSet.id + 1;
nextValidatorSet.id = leaf.nextAuthoritySetID;
nextValidatorSet.length = leaf.nextAuthoritySetLen;
nextValidatorSet.root = leaf.nextAuthoritySetRoot;

Expand Down
58 changes: 30 additions & 28 deletions core/packages/contracts/test/beefy/data/beefy-commitment.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
{
"@timestamp": "2022-08-15T14:33:32.464197692Z",
"commitmentHash": "0x7f62d4db7bea46299339228687382d5236e1a927181df37f12eb8a6ef028ff9f",
"txHash": "0x7f62d4db7bea46299339228687382d5236e1a927181df37f12eb8a6ef028ff9f",
"level": "info",
"message": "Sent SubmitFinal transaction",
"txHash": "0x7f62d4db7bea46299339228687382d5236e1a927181df37f12eb8a6ef028ff9f",
"commitmentHash": "0x870b04668512c384b8b5d2c9a6d015ea2575763f9527e5fb860e5f50671cee6d",
"params": {
"bitfield": [13],
"id": 2,
"bitfield": [7],
"id": 10,
"commitment": {
"blockNumber": 21,
"blockNumber": 109,
"payload": {
"mmrRootHash": "0x81ee69756866e69bcfe5cd41bf8bce2f95772778a53bbdac864a594d16d600a6",
"mmrRootHash": "0x64a57bff4956c0c2ac63121fc91d4d81f910c664dba0cecdb9f9cd0ccac462d6",
"prefix": "0x046d6880",
"suffix": "0x"
},
"validatorSetID": 2
"validatorSetID": 10
},
"leaf": {
"nextAuthoritySetID": 2,
"nextAuthoritySetID": 11,
"nextAuthoritySetLen": 4,
"nextAuthoritySetRoot": "0xf14e4528b1a93933bc4d2bb5c8e29cbc843eb49b95b2ec8a1764cf2d77672782",
"parachainHeadsRoot": "0xa47737a8df93c41882e6ddca4a26fc3f4bba247313275718fa2c30024c5e481b",
"parentHash": "0x45f8717d711955b2a52005897e88be87c4b02d763cf233ab1978062e754b7281",
"parentNumber": 20,
"parachainHeadsRoot": "0x4091cef7046c464d80126d3f667af6ad0f1c98d6dfa0d03f6978e51dd7f50717",
"parentHash": "0xce81cd173b6a9bd9e30b21ca5f8764c09aa15f93634ff11f283d35bc695c7869",
"parentNumber": 108,
"version": 0
},
"leafProof": [
"0x44d9f0c6bb0f38e718ba7f65d3d293159e78e824ed1efc58b39552dd2f58fad7",
"0xadf7753f060ff7c3adf45ec75956bafad26acbc10f91ee2a0022644604716939"
"0xed8137d63b7c5b2827b73d356d8002a81efe6e0bbc35b9c9e25220f0e9507904",
"0xd7a62dbb9ee5f415be48e618dd1e0645909b7b8cae1d894eefe6d07ea24588bd",
"0x66e326844558f90a7c378b2c5627f8502bd67b03983c8967619068901e811238",
"0x7111ab01035a1414ab452597887996e5732ccaa57d6c558366f74bc3322f0881"
],
"leafProofOrder": 0,
"proofs": [
Expand All @@ -38,30 +40,30 @@
"0x17988f4316b2a8b9378a84fbbe3f77df9e61146b6bb6c4d787fac3313b7b357a",
"0xccf90bfba49603ebf5fa031234e78e6948a5bbd817965f17edf88e583b76cd85"
],
"r": "0xa1ca907312c1b4b551d36f89653cbb7c720d17af47b506ec78e46aead713c069",
"s": "0x16bc861db6dcbec76440001e211fd3774d0fef7b8e25d3f9ec85bdfd760f72ab",
"v": 28
"r": "0x1031c0b31f7e9659be0997a2b49d2273ac25f2c00d3bd2177027165922340440",
"s": "0x4bdfc36258e29a155b9bc2c614b22f01506915e519bb62fcee22ab1cf23236cb",
"v": 27
},
{
"account": "0xEdBd1F214bB448c7f0874CE1742ca3C78367DC27",
"index": 2,
"account": "0xE76425aA6Aa70096718D9b767dc9FE7Bb6967344",
"index": 1,
"proof": [
"0x114dc1def15f3745b029cec267953c0b97c1d89ce81e64e177d13b504721b7e6",
"0x8a4500af3b6f92a5115c8ddeeb7fba3237dc7dbcfc0de98aa0cef6a53df45d24"
"0xb4c8120aaff96d837782638ec0ba11a03f24b067fc1fe11cc52bc5314150f852",
"0xccf90bfba49603ebf5fa031234e78e6948a5bbd817965f17edf88e583b76cd85"
],
"r": "0xa479de0b42a761a1b43f2ff89327e72a0a2a5f609a69b810d5f080a9cad9ed4c",
"s": "0x4b6daf4391ca260f375d061d242a610d49b09e40f22ca414d772255a1058c87f",
"v": 28
"r": "0x16ae611992d0cba5d97191f84b78cb01c305dbe25ccb200936d8cb14bd6b7592",
"s": "0x4d6de195d08e4d553fc2f189e3e92eff92910aa0cbae80b3ad105c18ef651e92",
"v": 27
},
{
"account": "0xA240F23aa6957247B55fc6bCD635529c89291921",
"index": 3,
"account": "0xEdBd1F214bB448c7f0874CE1742ca3C78367DC27",
"index": 2,
"proof": [
"0x7d6ac1e0f0caad5df2b3e8a24b71a91e3d454f71f123602abf17450676992cc8",
"0x114dc1def15f3745b029cec267953c0b97c1d89ce81e64e177d13b504721b7e6",
"0x8a4500af3b6f92a5115c8ddeeb7fba3237dc7dbcfc0de98aa0cef6a53df45d24"
],
"r": "0xa7ee2688f0d7ed912fa17605db42b18cc8348bbeaed13e2280b4c12f1c157166",
"s": "0x6a0318e975f6bf5d38828e35f218c1264ac11f57e3bcef101e8b55e66a58f556",
"r": "0x8b8e6aad74c935a67051d6aa5b7138758f234d6b5791b5b443cb7181ae4ca07c",
"s": "0x40a6f4d026cab07482e97ad6f84a52c183b1467a669eb2cff6403f3a7257b353",
"v": 28
}
]
Expand Down
15 changes: 8 additions & 7 deletions core/packages/test/scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ rebuild_relaychain(){
popd
}

# Only for debug purpose when relaychain branch not released
# Only for debug purpose when we need to do some customization in relaychain
build_relaychain_from_source(){
if [ ! -d "$relaychain_dir" ] ; then
echo "clone polkadot project to $relaychain_dir"
git clone https://github.com/paritytech/polkadot.git $relaychain_dir
relaychain_src_dir="$relaychain_dir/src"
if [ ! -d "$relaychain_src_dir" ] ; then
echo "clone polkadot project to $relaychain_src_dir"
git clone https://github.com/paritytech/polkadot.git $relaychain_src_dir
fi
pushd $relaychain_dir
git fetch origin && git checkout release-$relaychain_version
pushd $relaychain_src_dir
git switch release-$relaychain_version
cargo build --release
cp "$relaychain_dir/target/release/polkadot" "$output_bin_dir"
cp "$relaychain_src_dir/target/release/polkadot" "$output_bin_dir"
popd
}

Expand Down
25 changes: 24 additions & 1 deletion relayer/relays/beefy/polkadot-listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ func (li *PolkadotListener) scanCommitments(
}

if result.SignedCommitment.Commitment.ValidatorSetID == currentValidatorSet+1 {
// Workaround for https://github.com/paritytech/polkadot/pull/6577
if uint64(result.MMRProof.Leaf.BeefyNextAuthoritySet.ID) != result.SignedCommitment.Commitment.ValidatorSetID+1 {
log.WithFields(log.Fields{
"commitment": log.Fields{
"blockNumber": result.SignedCommitment.Commitment.BlockNumber,
"validatorSetID": result.SignedCommitment.Commitment.ValidatorSetID,
},
}).Info("Discarded invalid handover commitment with BeefyNextAuthoritySet not change")
continue
}
currentValidatorSet++

validators, err := li.queryBeefyAuthorities(result.BlockHash)
if err != nil {
return fmt.Errorf("fetch beefy authorities at block %v: %w", result.BlockHash, err)
Expand Down Expand Up @@ -155,3 +164,17 @@ func (li *PolkadotListener) queryBeefyAuthorities(blockHash types.Hash) ([]subst

return authorities, nil
}

func (li *PolkadotListener) queryBeefyNextAuthoritySet(blockHash types.Hash) (types.BeefyNextAuthoritySet, error) {
var nextAuthoritySet types.BeefyNextAuthoritySet
storageKey, err := types.CreateStorageKey(li.conn.Metadata(), "MmrLeaf", "BeefyNextAuthorities", nil, nil)
ok, err := li.conn.API().RPC.State.GetStorage(storageKey, &nextAuthoritySet, blockHash)
if err != nil {
return nextAuthoritySet, err
}
if !ok {
return nextAuthoritySet, fmt.Errorf("beefy nextAuthoritySet not found")
}

return nextAuthoritySet, nil
}

0 comments on commit c7409e4

Please sign in to comment.