datahaven/contracts/test/MessageEncoding.t.sol

28 lines
1.2 KiB
Solidity
Raw Permalink Normal View History

feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.27;
import {Test} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";
import {DataHavenSnowbridgeMessages} from "../src/libraries/DataHavenSnowbridgeMessages.sol";
Fix: 🏗️ Message encoding / decoding (#113) ## Summary of changes - We decided to remove the topics and nonce from the massage encoding since we don't use them (original commit: https://github.com/Moonsong-Labs/datahaven/commit/ee2a3f2fd432e0f8623a9798730ce697bfc52d34). - Besides, we already have a nonce at the Snowbridge message level https://github.com/Moonsong-Labs/datahaven/blob/f4ab5c2b2e93c775555ab4b8d0b2babaf5bc15b7/operator/primitives/snowbridge/inbound-queue/src/v2/message.rs#L105 - I had to recreate the static test for _encoding_ (happens in [DataHavenSnowbridgeMessages.sol](https://github.com/Moonsong-Labs/datahaven/blob/d12d40634f16eb9642b5b94cbc364b6679339393/contracts/src/libraries/DataHavenSnowbridgeMessages.sol) ) / _decoding_ (happens in [operator/primitives/bridge/src/lib.rs)](https://github.com/Moonsong-Labs/datahaven/blob/f9f9cc65fe33c86ac91f2097adbcb945b1746277/operator/primitives/bridge/src/lib.rs). Now it matches the current structure. The idea is that now we can test that we don't break the decoding in followup refactoring. - Fixes a problem with EigenLayer validator addresses. In all our contracts we were using `bytes32` to refer to a Solochain validator address. But on our Substrate change we actually expect AccountId20, so only 20 bytes. This was causing the decoding to fail. - I opted for the minimal change that would be to take the right-most 20 bytes to send that to our chain. But we might want aswell to limit our EigenLayer contracts to be only 20 bytes long. @ahmadkaouk showcase this [here](https://github.com/Moonsong-Labs/datahaven/commit/92a34c273ca439341bd8b61ff3592cef45ba4727) - Adds a bash script to run the static test. The test will compile the contracts, run the encoding test, compile the operator, and run the decoding test. This saves a huge amount of time since we don't need to run the full e2e setup. The way of running it is the following: ```bash cd operator/test/scripts ./test_message_encoding.sh ``` - As a consequence of this PR, the execution relayer now works properly. EDIT: > [!IMPORTANT] **We decided to use 20-byte addresses in our contracts**. So what is stated above is not valid anymore. The change implies that the mapping from Ethereum addresses to bytes32 addresses now it's a mapping as follows: https://github.com/Moonsong-Labs/datahaven/blob/dd3ba99ac0553a33448dc77efbbea08cacd278e6/contracts/src/DataHavenServiceManager.sol#L51-L52 I've updated helper functions, tests, etc to be compliant with this change. The execution relayer and beefy relayer look stable now. --------- Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-07-16 07:38:58 +00:00
import {TestUtils} from "./utils/TestUtils.sol";
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
Fix: 🏗️ Message encoding / decoding (#113) ## Summary of changes - We decided to remove the topics and nonce from the massage encoding since we don't use them (original commit: https://github.com/Moonsong-Labs/datahaven/commit/ee2a3f2fd432e0f8623a9798730ce697bfc52d34). - Besides, we already have a nonce at the Snowbridge message level https://github.com/Moonsong-Labs/datahaven/blob/f4ab5c2b2e93c775555ab4b8d0b2babaf5bc15b7/operator/primitives/snowbridge/inbound-queue/src/v2/message.rs#L105 - I had to recreate the static test for _encoding_ (happens in [DataHavenSnowbridgeMessages.sol](https://github.com/Moonsong-Labs/datahaven/blob/d12d40634f16eb9642b5b94cbc364b6679339393/contracts/src/libraries/DataHavenSnowbridgeMessages.sol) ) / _decoding_ (happens in [operator/primitives/bridge/src/lib.rs)](https://github.com/Moonsong-Labs/datahaven/blob/f9f9cc65fe33c86ac91f2097adbcb945b1746277/operator/primitives/bridge/src/lib.rs). Now it matches the current structure. The idea is that now we can test that we don't break the decoding in followup refactoring. - Fixes a problem with EigenLayer validator addresses. In all our contracts we were using `bytes32` to refer to a Solochain validator address. But on our Substrate change we actually expect AccountId20, so only 20 bytes. This was causing the decoding to fail. - I opted for the minimal change that would be to take the right-most 20 bytes to send that to our chain. But we might want aswell to limit our EigenLayer contracts to be only 20 bytes long. @ahmadkaouk showcase this [here](https://github.com/Moonsong-Labs/datahaven/commit/92a34c273ca439341bd8b61ff3592cef45ba4727) - Adds a bash script to run the static test. The test will compile the contracts, run the encoding test, compile the operator, and run the decoding test. This saves a huge amount of time since we don't need to run the full e2e setup. The way of running it is the following: ```bash cd operator/test/scripts ./test_message_encoding.sh ``` - As a consequence of this PR, the execution relayer now works properly. EDIT: > [!IMPORTANT] **We decided to use 20-byte addresses in our contracts**. So what is stated above is not valid anymore. The change implies that the mapping from Ethereum addresses to bytes32 addresses now it's a mapping as follows: https://github.com/Moonsong-Labs/datahaven/blob/dd3ba99ac0553a33448dc77efbbea08cacd278e6/contracts/src/DataHavenServiceManager.sol#L51-L52 I've updated helper functions, tests, etc to be compliant with this change. The execution relayer and beefy relayer look stable now. --------- Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-07-16 07:38:58 +00:00
// This test is used to encode the receive validators message and print the hex string.
// Run forge test --match-test testEncodeReceiveValidatorsMessage -vvv to see the hex encoded bytes.
// Use the helper script in operator/scripts/test_message_encoding.sh to test the encoding/decoding full cycle.
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
contract MessageEncodingTest is Test {
Fix: 🏗️ Message encoding / decoding (#113) ## Summary of changes - We decided to remove the topics and nonce from the massage encoding since we don't use them (original commit: https://github.com/Moonsong-Labs/datahaven/commit/ee2a3f2fd432e0f8623a9798730ce697bfc52d34). - Besides, we already have a nonce at the Snowbridge message level https://github.com/Moonsong-Labs/datahaven/blob/f4ab5c2b2e93c775555ab4b8d0b2babaf5bc15b7/operator/primitives/snowbridge/inbound-queue/src/v2/message.rs#L105 - I had to recreate the static test for _encoding_ (happens in [DataHavenSnowbridgeMessages.sol](https://github.com/Moonsong-Labs/datahaven/blob/d12d40634f16eb9642b5b94cbc364b6679339393/contracts/src/libraries/DataHavenSnowbridgeMessages.sol) ) / _decoding_ (happens in [operator/primitives/bridge/src/lib.rs)](https://github.com/Moonsong-Labs/datahaven/blob/f9f9cc65fe33c86ac91f2097adbcb945b1746277/operator/primitives/bridge/src/lib.rs). Now it matches the current structure. The idea is that now we can test that we don't break the decoding in followup refactoring. - Fixes a problem with EigenLayer validator addresses. In all our contracts we were using `bytes32` to refer to a Solochain validator address. But on our Substrate change we actually expect AccountId20, so only 20 bytes. This was causing the decoding to fail. - I opted for the minimal change that would be to take the right-most 20 bytes to send that to our chain. But we might want aswell to limit our EigenLayer contracts to be only 20 bytes long. @ahmadkaouk showcase this [here](https://github.com/Moonsong-Labs/datahaven/commit/92a34c273ca439341bd8b61ff3592cef45ba4727) - Adds a bash script to run the static test. The test will compile the contracts, run the encoding test, compile the operator, and run the decoding test. This saves a huge amount of time since we don't need to run the full e2e setup. The way of running it is the following: ```bash cd operator/test/scripts ./test_message_encoding.sh ``` - As a consequence of this PR, the execution relayer now works properly. EDIT: > [!IMPORTANT] **We decided to use 20-byte addresses in our contracts**. So what is stated above is not valid anymore. The change implies that the mapping from Ethereum addresses to bytes32 addresses now it's a mapping as follows: https://github.com/Moonsong-Labs/datahaven/blob/dd3ba99ac0553a33448dc77efbbea08cacd278e6/contracts/src/DataHavenServiceManager.sol#L51-L52 I've updated helper functions, tests, etc to be compliant with this change. The execution relayer and beefy relayer look stable now. --------- Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-07-16 07:38:58 +00:00
function testEncodeReceiveValidatorsMessage() public pure {
// Use the utility function for consistency
address[] memory mockValidators = TestUtils.generateMockValidatorsAddresses(3);
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
Fix: 🏗️ Message encoding / decoding (#113) ## Summary of changes - We decided to remove the topics and nonce from the massage encoding since we don't use them (original commit: https://github.com/Moonsong-Labs/datahaven/commit/ee2a3f2fd432e0f8623a9798730ce697bfc52d34). - Besides, we already have a nonce at the Snowbridge message level https://github.com/Moonsong-Labs/datahaven/blob/f4ab5c2b2e93c775555ab4b8d0b2babaf5bc15b7/operator/primitives/snowbridge/inbound-queue/src/v2/message.rs#L105 - I had to recreate the static test for _encoding_ (happens in [DataHavenSnowbridgeMessages.sol](https://github.com/Moonsong-Labs/datahaven/blob/d12d40634f16eb9642b5b94cbc364b6679339393/contracts/src/libraries/DataHavenSnowbridgeMessages.sol) ) / _decoding_ (happens in [operator/primitives/bridge/src/lib.rs)](https://github.com/Moonsong-Labs/datahaven/blob/f9f9cc65fe33c86ac91f2097adbcb945b1746277/operator/primitives/bridge/src/lib.rs). Now it matches the current structure. The idea is that now we can test that we don't break the decoding in followup refactoring. - Fixes a problem with EigenLayer validator addresses. In all our contracts we were using `bytes32` to refer to a Solochain validator address. But on our Substrate change we actually expect AccountId20, so only 20 bytes. This was causing the decoding to fail. - I opted for the minimal change that would be to take the right-most 20 bytes to send that to our chain. But we might want aswell to limit our EigenLayer contracts to be only 20 bytes long. @ahmadkaouk showcase this [here](https://github.com/Moonsong-Labs/datahaven/commit/92a34c273ca439341bd8b61ff3592cef45ba4727) - Adds a bash script to run the static test. The test will compile the contracts, run the encoding test, compile the operator, and run the decoding test. This saves a huge amount of time since we don't need to run the full e2e setup. The way of running it is the following: ```bash cd operator/test/scripts ./test_message_encoding.sh ``` - As a consequence of this PR, the execution relayer now works properly. EDIT: > [!IMPORTANT] **We decided to use 20-byte addresses in our contracts**. So what is stated above is not valid anymore. The change implies that the mapping from Ethereum addresses to bytes32 addresses now it's a mapping as follows: https://github.com/Moonsong-Labs/datahaven/blob/dd3ba99ac0553a33448dc77efbbea08cacd278e6/contracts/src/DataHavenServiceManager.sol#L51-L52 I've updated helper functions, tests, etc to be compliant with this change. The execution relayer and beefy relayer look stable now. --------- Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-07-16 07:38:58 +00:00
DataHavenSnowbridgeMessages.NewValidatorSetPayload memory payload =
feat: automated validator set submission with era targeting (#433) ## Era-targeted validator set submission with dedicated submitter role > **Note:** This PR includes a detailed specification at [`specs/validator-set-submission/validator-set-submission.md`](https://github.com/datahaven-xyz/datahaven/blob/feat/validator-set-submitter/specs/validator-set-submission/validator-set-submission.md) that covers the design rationale, submission lifecycle, era-targeting rules, and failure modes. Reading the spec first will make the contract, pallet, and daemon changes easier to follow. ### Summary - Introduce a dedicated `validatorSetSubmitter` role on `DataHavenServiceManager`, separating validator set submission authority from the contract owner - Replace the unscoped `sendNewValidatorSet` with `sendNewValidatorSetForEra`, which encodes a `targetEra` into the Snowbridge message payload - Add server-side era validation in the `external-validators` pallet to reject stale, duplicate, or out-of-range submissions - Add a long-running TypeScript daemon that watches session changes and automatically submits each era's validator set at the right time ### Contract changes (`contracts/`) - **New `validatorSetSubmitter` storage slot** — set during `initialize` and rotatable via `setValidatorSetSubmitter` (owner-only). The storage gap is decremented accordingly. - **`sendNewValidatorSet` → `sendNewValidatorSetForEra`** — accepts a `uint64 targetEra` parameter and is restricted to `onlyValidatorSetSubmitter` instead of `onlyOwner`. - **`buildNewValidatorSetMessageForEra`** — the `NewValidatorSetPayload.externalIndex` is now caller-supplied instead of hardcoded to `0`. - **New events** — `ValidatorSetSubmitterUpdated`, `ValidatorSetMessageSubmitted`. - **New error** — `OnlyValidatorSetSubmitter`. - **New test suite** — `ValidatorSetSubmitter.t.sol` covering submitter set/rotate, access control, era encoding, and legacy function removal. ### Pallet changes (`operator/`) - **`validate_target_era`** in `external-validators` — enforces `activeEra < targetEra <= activeEra + 1` and `targetEra > ExternalIndex` (dedup guard). - **New errors** — `TargetEraTooOld`, `TargetEraTooNew`, `DuplicateOrStaleTargetEra`. - **Tests** — five new test cases for era boundary conditions (next-era acceptance, old-era rejection, too-new rejection, duplicate rejection, genesis behavior). Existing `era_hooks_with_external_index` test updated to use valid target eras. - **Runtime test fixes** — `external_index: 0` → `1` in mainnet/stagenet/testnet EigenLayer message processor tests to satisfy the new validation. ### Validator set submitter daemon (`test/tools/validator-set-submitter/`) - Event-driven service that subscribes to finalized `Session.CurrentIndex` via Polkadot-API `watchValue`. - Submits once per era during the last session, targeting `ActiveEra + 1`. - Tracks submitted eras to avoid duplicates; skips if `ExternalIndex` already covers the target. - Startup self-checks: Ethereum connectivity, DataHaven connectivity, on-chain submitter authorization. - Supports `--dry-run` mode and YAML configuration. - Graceful shutdown on `SIGINT`/`SIGTERM`. ### Test & tooling updates - **E2E test** (`validator-set-update.test.ts`) — calls `sendNewValidatorSetForEra` with a computed `targetEra` and filters the substrate event by `external_index`. - **`update-validator-set.ts` script** — accepts `--target-era` flag; defaults to era 1 for fresh networks. - **CLI launch** — wires validator set update as an interactive step after relayer launch. - **`package.json`** — new `submitter` and `submitter:dry-run` scripts. - Regenerated contract bindings, PAPI metadata, state-diff, and storage layout snapshots. ### Test plan - [x] `forge test` — passes, including new `ValidatorSetSubmitter.t.sol` - [x] `cargo test` — passes, including new era-validation tests in `external-validators` - [x] `bun test:e2e` — validator-set-update suite passes with era-targeted flow - [x] Manual: run submitter daemon against local network (`bun submitter`), verify it submits once per era at the correct session ## ⚠️ Breaking Changes ⚠️ - **`sendNewValidatorSet` removed** — replaced by `sendNewValidatorSetForEra(uint64 targetEra, ...)`. Callers must now supply a `targetEra` parameter. - **Access control changed** — validator set submission is now restricted to the `validatorSetSubmitter` role instead of the contract `owner`. The submitter address is set during `initialize` and rotatable via `setValidatorSetSubmitter` (owner-only). - **`external-validators` pallet now validates `targetEra`** — messages with a stale, duplicate, or out-of-range `external_index` are rejected on-chain. Existing integrations sending `external_index: 0` will fail validation. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-20 09:31:44 +00:00
DataHavenSnowbridgeMessages.NewValidatorSetPayload({
validators: mockValidators, externalIndex: uint64(0)
});
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
bytes memory encodedMessage =
refactor(contracts): Harden DataHavenServiceManager with input validation and code cleanup (#395) ## Summary - Add zero address validation across all functions that accept address parameters to prevent misconfiguration - Fix race condition in `buildNewValidatorSetMessage()` that could cause reverts during validator deregistration - Refactor contract for improved readability and reduced code duplication - Update AVS metadata URL to point to the correct hosted JSON file ## Changes ### Security & Validation - Add `ZeroAddress` error and validate all address inputs in `initialize`, `setRewardsInitiator`, `setSnowbridgeGateway`, `addValidatorToAllowlist`, `registerOperator`, and `updateSolochainAddressForValidator` - Fix race condition: filter out zero solochain addresses in `buildNewValidatorSetMessage()` to prevent reverts when a validator is mid-deregistration ### Refactoring - Replace verbose `if/revert` patterns with `require` statements for consistency - Inline single-use internal functions (`_createDataHavenOperatorSets`, `_setRewardsInitiator`) - Consolidate duplicate error types into single `ZeroAddress` error - Rename `initialise` → `initialize` to maintain consistency with the transparent upgradability pattern - Optimize validator set message encoding by removing redundant wrapper function ### Observability - Add `SolochainAddressUpdated` event for tracking validator address changes ### Cleanup - Remove unused remappings from `foundry.toml` - Fix typo in metadata description --------- Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2026-01-20 10:32:32 +00:00
DataHavenSnowbridgeMessages.scaleEncodeNewValidatorSetMessagePayload(payload);
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
Fix: 🏗️ Message encoding / decoding (#113) ## Summary of changes - We decided to remove the topics and nonce from the massage encoding since we don't use them (original commit: https://github.com/Moonsong-Labs/datahaven/commit/ee2a3f2fd432e0f8623a9798730ce697bfc52d34). - Besides, we already have a nonce at the Snowbridge message level https://github.com/Moonsong-Labs/datahaven/blob/f4ab5c2b2e93c775555ab4b8d0b2babaf5bc15b7/operator/primitives/snowbridge/inbound-queue/src/v2/message.rs#L105 - I had to recreate the static test for _encoding_ (happens in [DataHavenSnowbridgeMessages.sol](https://github.com/Moonsong-Labs/datahaven/blob/d12d40634f16eb9642b5b94cbc364b6679339393/contracts/src/libraries/DataHavenSnowbridgeMessages.sol) ) / _decoding_ (happens in [operator/primitives/bridge/src/lib.rs)](https://github.com/Moonsong-Labs/datahaven/blob/f9f9cc65fe33c86ac91f2097adbcb945b1746277/operator/primitives/bridge/src/lib.rs). Now it matches the current structure. The idea is that now we can test that we don't break the decoding in followup refactoring. - Fixes a problem with EigenLayer validator addresses. In all our contracts we were using `bytes32` to refer to a Solochain validator address. But on our Substrate change we actually expect AccountId20, so only 20 bytes. This was causing the decoding to fail. - I opted for the minimal change that would be to take the right-most 20 bytes to send that to our chain. But we might want aswell to limit our EigenLayer contracts to be only 20 bytes long. @ahmadkaouk showcase this [here](https://github.com/Moonsong-Labs/datahaven/commit/92a34c273ca439341bd8b61ff3592cef45ba4727) - Adds a bash script to run the static test. The test will compile the contracts, run the encoding test, compile the operator, and run the decoding test. This saves a huge amount of time since we don't need to run the full e2e setup. The way of running it is the following: ```bash cd operator/test/scripts ./test_message_encoding.sh ``` - As a consequence of this PR, the execution relayer now works properly. EDIT: > [!IMPORTANT] **We decided to use 20-byte addresses in our contracts**. So what is stated above is not valid anymore. The change implies that the mapping from Ethereum addresses to bytes32 addresses now it's a mapping as follows: https://github.com/Moonsong-Labs/datahaven/blob/dd3ba99ac0553a33448dc77efbbea08cacd278e6/contracts/src/DataHavenServiceManager.sol#L51-L52 I've updated helper functions, tests, etc to be compliant with this change. The execution relayer and beefy relayer look stable now. --------- Co-authored-by: Ahmad Kaouk <ahmadkaouk.93@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-07-16 07:38:58 +00:00
console.logBytes(encodedMessage);
feat: 🏗️ run execution relayer (#73) ## This PR includes: - Running the execution relayer on the CLI - Modifying the Payload generation in the `DataHavenServiceManager.sol` - Modified the `EigenLayerMessageProcessor` to work with the ValidatorSet update message, but for this change we are loosing the generic message type (it was the only way to make it work so far). - Adds a `--no-wait` argument to the cli launch and stop commands to bootstrap faster. ### Testing the Snowbridge message encoding / decoding - Added`MessageEncoding.t.sol` is documented and explains how to generate bin data to use in the rust test. - Added a Rust unit test to `EigenLayerMessageProcessor` to compare the message encoding/decoding taking the bytes from a file (previously generated with some mock data). Specifically, we want that: https://github.com/Moonsong-Labs/datahaven/blob/3cbca0db6d0bcc6cd6969b13b214a27465460b45/contracts/src/libraries/DataHavenSnowbridgeMessages.sol#L78-L85 Generates the right bytes encoding for https://github.com/Moonsong-Labs/datahaven/blob/0e2c9cd518ada0893f1759eee229976fb5a90495/operator/primitives/bridge/src/lib.rs#L51 If the test passes, it's very likely that the CLI will also pass, if not, then we might wanna check something else is missing. ### Breaking change ⚠️ For compatibility reasons with Snowbridge contracts (they call specific extrinsics of specific pallets), I had to rename: - `InboundQueueV2` -> `EthereumInboundQueueV2` - `OutboundQueueV2` -> `EthereumOutboundQueueV2` ## For follow up PRs: - Add an automated way of generating the Solidity bytes fo testing, so we don't need to maintain the MessageEncoding.t.sol and generate the binary data manually. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for the "execution" relayer type in relay configuration, parsing, and CLI launch utilities. - Introduced a Solidity test contract for encoding and logging validator set messages. - Added a comprehensive "start:all" script to streamline launching and setup processes. - **Enhancements** - Improved message encoding for validator set updates, aligning with new struct field names and message formats. - Updated relay configuration schema and validation to support execution relayers and OFAC settings. - Increased beacon datastore capacity and adjusted relay scheduling parameters in configuration files. - **Refactor** - Renamed runtime type aliases for inbound/outbound queues to more descriptive names across mainnet, stagenet, and testnet. - Centralized and streamlined validator set update logic in CLI utilities. - Centralized message decoding logic and improved visibility of message fields in Rust components. - **Bug Fixes** - Improved error handling and decoding logic for message processing in Rust components. - **Tests** - Added Rust and Solidity tests for message encoding and processing validation. - **Chores** - Updated dependencies and feature flags in Rust project configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Facundo Farall <37149322+ffarall@users.noreply.github.com>
2025-06-05 15:00:03 +00:00
}
}