Skip to content

Commit

Permalink
Merge branch 'tiago/migrate-new-contracts' (#1885)
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Sep 21, 2023
2 parents 49054ea + 05c4519 commit affd80a
Show file tree
Hide file tree
Showing 47 changed files with 681 additions and 805 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Migrate to the new Ethereum contracts
([\#1885](https://github.com/anoma/namada/pull/1885))
41 changes: 8 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ directories = "4.0.1"
ed25519-consensus = "1.2.0"
escargot = "0.5.7"
ethabi = "18.0.0"
ethbridge-bridge-contract = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0"}
ethbridge-bridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0"}
ethbridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0"}
ethbridge-governance-contract = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0"}
ethbridge-governance-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0"}
ethbridge-structs = { git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.23.0" }
ethbridge-bridge-contract = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.24.0"}
ethbridge-bridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.24.0"}
ethbridge-events = {git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.24.0"}
ethbridge-structs = { git = "https://github.com/heliaxdev/ethbridge-rs", tag = "v0.24.0" }
ethers = "2.0.0"
expectrl = "0.7.0"
eyre = "0.6.5"
Expand Down
1 change: 0 additions & 1 deletion apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ ed25519-consensus.workspace = true
ethabi.workspace = true
ethbridge-bridge-events.workspace = true
ethbridge-events.workspace = true
ethbridge-governance-events.workspace = true
eyre.workspace = true
fd-lock.workspace = true
ferveo-common.workspace = true
Expand Down
102 changes: 78 additions & 24 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,10 +2292,12 @@ pub mod cmds {
/// Used as sub-commands (`SubCmd` instance) in `namadar` binary.
#[derive(Clone, Debug)]
pub enum ValidatorSet {
/// Query an Ethereum ABI encoding of the consensus validator
/// set in Namada, at the given epoch, or the latest
/// one, if none is provided.
ConsensusValidatorSet(ConsensusValidatorSet),
/// Query the Bridge validator set in Namada, at the given epoch,
/// or the latest one, if none is provided.
BridgeValidatorSet(BridgeValidatorSet),
/// Query the Governance validator set in Namada, at the given epoch,
/// or the latest one, if none is provided.
GovernanceValidatorSet(GovernanceValidatorSet),
/// Query an Ethereum ABI encoding of a proof of the consensus
/// validator set in Namada, at the given epoch, or the next
/// one, if none is provided.
Expand All @@ -2310,14 +2312,19 @@ pub mod cmds {

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).and_then(|matches| {
let consensus_validator_set =
ConsensusValidatorSet::parse(matches)
.map(Self::ConsensusValidatorSet);
let bridge_validator_set = BridgeValidatorSet::parse(matches)
.map(Self::BridgeValidatorSet);
let governance_validator_set =
GovernanceValidatorSet::parse(matches)
.map(Self::GovernanceValidatorSet);
let validator_set_proof = ValidatorSetProof::parse(matches)
.map(Self::ValidatorSetProof);
let relay = ValidatorSetUpdateRelay::parse(matches)
.map(Self::ValidatorSetUpdateRelay);
consensus_validator_set.or(validator_set_proof).or(relay)
bridge_validator_set
.or(governance_validator_set)
.or(validator_set_proof)
.or(relay)
})
}

Expand All @@ -2329,34 +2336,56 @@ pub mod cmds {
contracts.",
)
.subcommand_required(true)
.subcommand(ConsensusValidatorSet::def().display_order(1))
.subcommand(BridgeValidatorSet::def().display_order(1))
.subcommand(GovernanceValidatorSet::def().display_order(1))
.subcommand(ValidatorSetProof::def().display_order(1))
.subcommand(ValidatorSetUpdateRelay::def().display_order(1))
}
}

#[derive(Clone, Debug)]
pub struct ConsensusValidatorSet(
pub args::ConsensusValidatorSet<args::CliTypes>,
pub struct BridgeValidatorSet(pub args::BridgeValidatorSet<args::CliTypes>);

impl SubCmd for BridgeValidatorSet {
const CMD: &'static str = "bridge";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::BridgeValidatorSet::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD)
.about(
"Query the Bridge validator set in Namada, at the given \
epoch, or the latest one, if none is provided.",
)
.add_args::<args::BridgeValidatorSet<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct GovernanceValidatorSet(
pub args::GovernanceValidatorSet<args::CliTypes>,
);

impl SubCmd for ConsensusValidatorSet {
const CMD: &'static str = "consensus";
impl SubCmd for GovernanceValidatorSet {
const CMD: &'static str = "governance";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
Self(args::ConsensusValidatorSet::parse(matches))
Self(args::GovernanceValidatorSet::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about(
"Query an Ethereum ABI encoding of the consensus \
validator set in Namada, at the requested epoch, or the \
current one, if no epoch is provided.",
"Query the Governance validator set in Namada, at the \
given epoch, or the latest one, if none is provided.",
)
.add_args::<args::ConsensusValidatorSet<args::CliTypes>>()
.add_args::<args::GovernanceValidatorSet<args::CliTypes>>()
}
}

Expand Down Expand Up @@ -3193,18 +3222,18 @@ pub mod args {
}
}

impl CliToSdkCtxless<ConsensusValidatorSet<SdkTypes>>
for ConsensusValidatorSet<CliTypes>
impl CliToSdkCtxless<BridgeValidatorSet<SdkTypes>>
for BridgeValidatorSet<CliTypes>
{
fn to_sdk_ctxless(self) -> ConsensusValidatorSet<SdkTypes> {
ConsensusValidatorSet::<SdkTypes> {
fn to_sdk_ctxless(self) -> BridgeValidatorSet<SdkTypes> {
BridgeValidatorSet::<SdkTypes> {
query: self.query.to_sdk_ctxless(),
epoch: self.epoch,
}
}
}

impl Args for ConsensusValidatorSet<CliTypes> {
impl Args for BridgeValidatorSet<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let epoch = EPOCH.parse(matches);
Expand All @@ -3214,12 +3243,37 @@ pub mod args {
fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>().arg(
EPOCH.def().help(
"The epoch of the consensus set of validators to query.",
"The epoch of the Bridge set of validators to query.",
),
)
}
}

impl CliToSdkCtxless<GovernanceValidatorSet<SdkTypes>>
for GovernanceValidatorSet<CliTypes>
{
fn to_sdk_ctxless(self) -> GovernanceValidatorSet<SdkTypes> {
GovernanceValidatorSet::<SdkTypes> {
query: self.query.to_sdk_ctxless(),
epoch: self.epoch,
}
}
}

impl Args for GovernanceValidatorSet<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let epoch = EPOCH.parse(matches);
Self { query, epoch }
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>().arg(EPOCH.def().help(
"The epoch of the Governance set of validators to query.",
))
}
}

impl CliToSdkCtxless<ValidatorSetProof<SdkTypes>>
for ValidatorSetProof<CliTypes>
{
Expand Down
22 changes: 20 additions & 2 deletions apps/src/lib/cli/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<IO: Io> CliApi<IO> {
}
},
cli::NamadaRelayer::ValidatorSet(sub) => match sub {
ValidatorSet::ConsensusValidatorSet(ConsensusValidatorSet(
ValidatorSet::BridgeValidatorSet(BridgeValidatorSet(
mut args,
)) => {
let client = client.unwrap_or_else(|| {
Expand All @@ -138,7 +138,25 @@ impl<IO: Io> CliApi<IO> {
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
validator_set::query_validator_set_args::<_, IO>(
validator_set::query_bridge_validator_set::<_, IO>(
&client, args,
)
.await;
}
ValidatorSet::GovernanceValidatorSet(
GovernanceValidatorSet(mut args),
) => {
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(
&mut args.query.ledger_address,
)
});
client
.wait_until_node_is_synced::<IO>()
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
validator_set::query_governnace_validator_set::<_, IO>(
&client, args,
)
.await;
Expand Down
4 changes: 0 additions & 4 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,10 +1126,6 @@ pub fn genesis(num_validators: u64) -> Genesis {
address: EthAddress([0; 20]),
version: Default::default(),
},
governance: UpgradeableContract {
address: EthAddress([1; 20]),
version: Default::default(),
},
},
}),
native_token: address::nam(),
Expand Down
Loading

0 comments on commit affd80a

Please sign in to comment.