Finish merging in the develop branch

This commit is contained in:
Luke Parker
2025-01-30 03:14:24 -05:00
parent 258c02ff39
commit a275023cfc
62 changed files with 452 additions and 508 deletions

View File

@@ -1,10 +1,7 @@
pub use serai_abi::in_instructions::primitives;
use primitives::SignedBatch;
use crate::{
primitives::{BlockHash, ExternalNetworkId},
Transaction, SeraiError, Serai, TemporalSerai,
};
use crate::{primitives::ExternalNetworkId, Transaction, SeraiError, Serai, TemporalSerai};
pub type InInstructionsEvent = serai_abi::in_instructions::Event;
@@ -12,6 +9,7 @@ const PALLET: &str = "InInstructions";
#[derive(Clone, Copy)]
pub struct SeraiInInstructions<'a>(pub(crate) &'a TemporalSerai<'a>);
impl SeraiInInstructions<'_> {
pub async fn last_batch_for_network(
&self,
network: ExternalNetworkId,

View File

@@ -16,7 +16,7 @@ pub use abi::{primitives, Transaction};
use abi::*;
pub use primitives::{SeraiAddress, Signature, Amount};
use primitives::{Header, NetworkId};
use primitives::{Header, ExternalNetworkId};
pub mod coins;
pub use coins::SeraiCoins;
@@ -313,7 +313,7 @@ impl Serai {
/// Return the P2P Multiaddrs for the validators of the specified network.
pub async fn p2p_validators(
&self,
network: NetworkId,
network: ExternalNetworkId,
) -> Result<Vec<multiaddr::Multiaddr>, SeraiError> {
self.call("p2p_validators", network).await
}

View File

@@ -5,10 +5,10 @@ use sp_runtime::BoundedVec;
use serai_abi::{primitives::Amount, validator_sets::primitives::ExternalValidatorSet};
pub use serai_abi::validator_sets::primitives;
use primitives::{MAX_KEY_LEN, Session, ValidatorSet, KeyPair, SlashReport};
use primitives::{MAX_KEY_LEN, Session, KeyPair, SlashReport};
use crate::{
primitives::{NetworkId, ExternalNetworkId, EmbeddedEllipticCurve, SeraiAddress},
primitives::{NetworkId, ExternalNetworkId, EmbeddedEllipticCurve},
Transaction, Serai, TemporalSerai, SeraiError,
};
@@ -203,7 +203,7 @@ impl SeraiValidatorSets<'_> {
}
pub fn set_keys(
network: NetworkId,
network: ExternalNetworkId,
key_pair: KeyPair,
signature_participants: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
signature: Signature,
@@ -237,7 +237,7 @@ impl SeraiValidatorSets<'_> {
}
pub fn report_slashes(
network: NetworkId,
network: ExternalNetworkId,
slashes: SlashReport,
signature: Signature,
) -> Transaction {

View File

@@ -8,7 +8,7 @@ use blake2::{
use scale::Encode;
use serai_client::{
primitives::{BlockHash, NetworkId, ExternalCoin, Amount, ExternalBalance, SeraiAddress},
primitives::{BlockHash, ExternalCoin, Amount, ExternalBalance, SeraiAddress},
coins::CoinsEvent,
validator_sets::primitives::Session,
in_instructions::{

View File

@@ -11,7 +11,7 @@ use sp_core::Pair;
use serai_client::{
primitives::{
BlockHash, ExternalNetworkId, ExternalCoin, Amount, ExternalBalance, SeraiAddress, ExternalAddress,
BlockHash, ExternalCoin, Amount, ExternalBalance, SeraiAddress, ExternalAddress,
insecure_pair_from_name,
},
coins::{

View File

@@ -11,10 +11,11 @@ use sp_core::{sr25519::Signature, Pair as PairTrait};
use serai_abi::{
primitives::{
BlockHash, ExternalNetworkId, ExternalCoin, Amount, ExternalBalance, SeraiAddress, insecure_pair_from_name,
EXTERNAL_COINS, BlockHash, ExternalNetworkId, NetworkId, ExternalCoin, Amount, ExternalBalance,
SeraiAddress, insecure_pair_from_name,
},
validator_sets::primitives::{musig_context, Session, ValidatorSet},
genesis_liquidity::primitives::{oraclize_values_message, Values},
validator_sets::primitives::{Session, ValidatorSet, musig_context},
genesis_liquidity::primitives::{Values, oraclize_values_message},
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
};

View File

@@ -9,7 +9,7 @@ use scale::Encode;
use sp_core::Pair;
use serai_client::{
primitives::{BlockHash, NetworkId, ExternalBalance, SeraiAddress, insecure_pair_from_name},
primitives::{BlockHash, ExternalBalance, SeraiAddress, insecure_pair_from_name},
validator_sets::primitives::{ExternalValidatorSet, KeyPair},
in_instructions::{
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},

View File

@@ -16,12 +16,12 @@ use frost::dkg::musig::musig;
use schnorrkel::Schnorrkel;
use serai_client::{
primitives::EmbeddedEllipticCurve,
primitives::{EmbeddedEllipticCurve, Amount},
validator_sets::{
primitives::{MAX_KEY_LEN, ExternalValidatorSet, KeyPair, musig_context, set_keys_message},
ValidatorSetsEvent,
},
Amount, Serai, SeraiValidatorSets,
SeraiValidatorSets, Serai,
};
use crate::common::tx::publish_tx;

View File

@@ -6,7 +6,7 @@ use serai_abi::in_instructions::primitives::DexCall;
use serai_client::{
primitives::{
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, ExternalAddress,
BlockHash, ExternalCoin, Coin, Amount, ExternalBalance, Balance, SeraiAddress, ExternalAddress,
insecure_pair_from_name,
},
in_instructions::primitives::{

View File

@@ -44,7 +44,7 @@ async fn dht() {
assert!(!Serai::new(serai_rpc.clone())
.await
.unwrap()
.p2p_validators(ExternalNetworkId::Bitcoin.into())
.p2p_validators(ExternalNetworkId::Bitcoin)
.await
.unwrap()
.is_empty());

View File

@@ -5,8 +5,8 @@ use serai_client::TemporalSerai;
use serai_abi::{
primitives::{
NETWORKS, COINS, TARGET_BLOCK_TIME, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD, BlockHash,
Coin,
EXTERNAL_NETWORKS, NETWORKS, TARGET_BLOCK_TIME, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD,
BlockHash, ExternalNetworkId, NetworkId, ExternalCoin, Amount, ExternalBalance,
},
validator_sets::primitives::Session,
emissions::primitives::{INITIAL_REWARD_PER_BLOCK, SECURE_BY},
@@ -38,17 +38,16 @@ async fn send_batches(serai: &Serai, ids: &mut HashMap<ExternalNetworkId, u32>)
let mut block = BlockHash([0; 32]);
OsRng.fill_bytes(&mut block.0);
provide_batch(
serai,
Batch {
network,
id: ids[&network],
external_network_block_hash: block,
instructions: vec![],
},
)
.await;
}
provide_batch(
serai,
Batch {
network,
id: ids[&network],
external_network_block_hash: block,
instructions: vec![],
},
)
.await;
}
}

View File

@@ -7,11 +7,11 @@ use sp_core::{
use serai_client::{
primitives::{
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, BlockHash, NetworkId, EmbeddedEllipticCurve,
insecure_pair_from_name,
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, BlockHash, ExternalNetworkId, NetworkId,
EmbeddedEllipticCurve, Amount, insecure_pair_from_name,
},
validator_sets::{
primitives::{Session, ValidatorSet, ExternalValidatorSet, KeyPair},
primitives::{Session, ExternalValidatorSet, ValidatorSet, KeyPair},
ValidatorSetsEvent,
},
in_instructions::{
@@ -313,8 +313,12 @@ async fn validator_set_rotation() {
// provide a batch to complete the handover and retire the previous set
let mut block_hash = BlockHash([0; 32]);
OsRng.fill_bytes(&mut block_hash.0);
let batch =
Batch { network: network.try_into().unwrap(), id: 0, external_network_block_hash: block_hash, instructions: vec![] };
let batch = Batch {
network: network.try_into().unwrap(),
id: 0,
external_network_block_hash: block_hash,
instructions: vec![],
};
publish_tx(
&serai,
&SeraiInInstructions::execute_batch(SignedBatch {

View File

@@ -58,7 +58,7 @@ fn burn_with_instruction() {
// we shouldn't be able to burn more than what we have
let mut instruction = OutInstructionWithBalance {
instruction: OutInstruction { address: ExternalAddress::new(vec![]).unwrap(), data: None },
instruction: OutInstruction { address: ExternalAddress::new(vec![]).unwrap() },
balance: ExternalBalance {
coin: coin.try_into().unwrap(),
amount: Amount(balance.amount.0 + 1),

View File

@@ -67,7 +67,7 @@ pub mod pallet {
in_instruction_results: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
},
Halt {
network: NetworkId,
network: ExternalNetworkId,
},
}
@@ -103,7 +103,7 @@ pub mod pallet {
fn execute(instruction: &InInstructionWithBalance) -> Result<(), DispatchError> {
match &instruction.instruction {
InInstruction::Transfer(address) => {
Coins::<T>::mint(address.into(), instruction.balance.into())?;
Coins::<T>::mint((*address).into(), instruction.balance.into())?;
}
InInstruction::Dex(call) => {
// This will only be initiated by external chain transactions. That is why we only need
@@ -222,11 +222,11 @@ pub mod pallet {
}
InInstruction::GenesisLiquidity(address) => {
Coins::<T>::mint(GENESIS_LIQUIDITY_ACCOUNT.into(), instruction.balance.into())?;
GenesisLiq::<T>::add_coin_liquidity(address.into(), instruction.balance)?;
GenesisLiq::<T>::add_coin_liquidity((*address).into(), instruction.balance)?;
}
InInstruction::SwapToStakedSRI(address, network) => {
Coins::<T>::mint(POL_ACCOUNT.into(), instruction.balance.into())?;
Emissions::<T>::swap_to_staked_sri(address.into(), network, instruction.balance)?;
Emissions::<T>::swap_to_staked_sri((*address).into(), *network, instruction.balance)?;
}
}
Ok(())
@@ -319,7 +319,10 @@ pub mod pallet {
// key is publishing `Batch`s. This should only happen once the current key has verified all
// `Batch`s published by the prior key, meaning they are accepting the hand-over.
if prior.is_some() && (!valid_by_prior) {
ValidatorSets::<T>::retire_set(ValidatorSet { network: network.into(), session: prior_session });
ValidatorSets::<T>::retire_set(ValidatorSet {
network: network.into(),
session: prior_session,
});
}
// check that this validator set isn't publishing a batch more than once per block

View File

@@ -20,7 +20,7 @@ use sp_std::vec::Vec;
use sp_runtime::RuntimeDebug;
#[rustfmt::skip]
use serai_primitives::{BlockHash, NetworkId, Balance, SeraiAddress, ExternalAddress, system_address};
use serai_primitives::{BlockHash, ExternalNetworkId, NetworkId, ExternalBalance, Balance, SeraiAddress, ExternalAddress, system_address};
mod shorthand;
pub use shorthand::*;

View File

@@ -88,7 +88,10 @@ fn devnet_genesis(
networks: key_shares.clone(),
participants: validators.clone(),
},
emissions: EmissionsConfig { networks: key_shares, participants: validators.clone() },
emissions: EmissionsConfig {
networks: key_shares,
participants: validators.iter().map(|(validator, _)| *validator).collect(),
},
signals: SignalsConfig::default(),
babe: BabeConfig {
authorities: validators.iter().map(|validator| (validator.0.into(), 1)).collect(),

View File

@@ -26,9 +26,7 @@ pub enum EmbeddedEllipticCurve {
}
/// The type used to identify external networks.
#[derive(
Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, PartialOrd, Ord, MaxEncodedLen, TypeInfo,
)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ExternalNetworkId {
@@ -162,6 +160,17 @@ impl ExternalNetworkId {
}
impl NetworkId {
/// The embedded elliptic curve actively used for this network.
///
/// This is guaranteed to return `[]`, `[Embedwards25519]`, or
/// `[Embedwards25519, *network specific curve*]`.
pub fn embedded_elliptic_curves(&self) -> &'static [EmbeddedEllipticCurve] {
match self {
Self::Serai => &[],
Self::External(network) => network.embedded_elliptic_curves(),
}
}
pub fn coins(&self) -> Vec<Coin> {
match self {
Self::Serai => vec![Coin::Serai],

View File

@@ -1154,8 +1154,8 @@ pub mod pallet {
// session on this assumption
assert_eq!(Pallet::<T>::latest_decided_session(network.into()), Some(current_session));
let participants =
Participants::<T>::get(network).expect("session existed without participants");
let participants = Participants::<T>::get(NetworkId::from(network))
.expect("session existed without participants");
// Check the bitvec is of the proper length
if participants.len() != signature_participants.len() {
@@ -1189,7 +1189,7 @@ pub mod pallet {
// Verify the signature with the MuSig key of the signers
// We theoretically don't need set_keys_message to bind to removed_participants, as the
// key we're signing with effectively already does so, yet there's no reason not to
if !musig_key(set, &signers).verify(&set_keys_message(&set, key_pair), signature) {
if !musig_key(set.into(), &signers).verify(&set_keys_message(&set, key_pair), signature) {
Err(InvalidTransaction::BadProof)?;
}
@@ -1207,8 +1207,10 @@ pub mod pallet {
};
// There must have been a previous session is PendingSlashReport is populated
let set =
ExternalValidatorSet { network, session: Session(Self::session(network).unwrap().0 - 1) };
let set = ExternalValidatorSet {
network,
session: Session(Self::session(NetworkId::from(network)).unwrap().0 - 1),
};
if !key.verify(&slashes.report_slashes_message(), signature) {
Err(InvalidTransaction::BadProof)?;
}

View File

@@ -140,7 +140,7 @@ pub fn musig_key(set: ValidatorSet, set_keys: &[Public]) -> Public {
}
/// The message for the `set_keys` signature.
pub fn set_keys_message(set: &ValidatorSet, key_pair: &KeyPair) -> Vec<u8> {
pub fn set_keys_message(set: &ExternalValidatorSet, key_pair: &KeyPair) -> Vec<u8> {
(b"ValidatorSets-set_keys", set, key_pair).encode()
}