Skip to content

Commit

Permalink
Merge branch 'develop' into one-round-dkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve authored Aug 15, 2024
2 parents 5f1fcff + a2df54d commit e098369
Show file tree
Hide file tree
Showing 43 changed files with 1,295 additions and 315 deletions.
30 changes: 29 additions & 1 deletion Cargo.lock

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

13 changes: 12 additions & 1 deletion coordinator/tributary/tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,17 @@ impl<N: Network + 'static> TendermintMachine<N> {
if let Data::Proposal(_, block) = &msg.data {
match self.network.validate(block).await {
Ok(()) => {}
Err(BlockError::Temporal) => return Err(TendermintError::Temporal),
Err(BlockError::Temporal) => {
if self.block.round().step == Step::Propose {
self.broadcast(Data::Prevote(None));
}
Err(TendermintError::Temporal)?;
}
Err(BlockError::Fatal) => {
log::warn!(target: "tendermint", "validator proposed a fatally invalid block");
if self.block.round().step == Step::Propose {
self.broadcast(Data::Prevote(None));
}
self
.slash(
msg.sender,
Expand All @@ -729,6 +737,9 @@ impl<N: Network + 'static> TendermintMachine<N> {
target: "tendermint",
"proposed proposed with a syntactically invalid valid round",
);
if self.block.round().step == Step::Propose {
self.broadcast(Data::Prevote(None));
}
self
.slash(msg.sender, SlashEvent::WithEvidence(Evidence::InvalidValidRound(msg.encode())))
.await;
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exceptions = [
{ allow = ["AGPL-3.0"], name = "serai-dex-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-genesis-liquidity-pallet" },
{ allow = ["AGPL-3.0"], name = "serai-emissions-pallet" },

{ allow = ["AGPL-3.0"], name = "serai-in-instructions-pallet" },

Expand Down
6 changes: 3 additions & 3 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GEM
eventmachine (1.2.7)
ffi (1.17.0-x86_64-linux-gnu)
forwardable-extended (2.6.0)
google-protobuf (4.27.2-x86_64-linux)
google-protobuf (4.27.3-x86_64-linux)
bigdecimal
rake (>= 13)
http_parser.rb (0.8.0)
Expand Down Expand Up @@ -58,12 +58,12 @@ GEM
mercenary (0.4.0)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (6.0.0)
public_suffix (6.0.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rexml (3.3.2)
rexml (3.3.4)
strscan
rouge (4.3.0)
safe_yaml (1.0.5)
Expand Down
Empty file removed docs/protocol_changes/signals.md
Empty file.
2 changes: 2 additions & 0 deletions substrate/abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ serai-primitives = { path = "../primitives", version = "0.1", default-features =
serai-coins-primitives = { path = "../coins/primitives", version = "0.1", default-features = false }
serai-validator-sets-primitives = { path = "../validator-sets/primitives", version = "0.1", default-features = false }
serai-genesis-liquidity-primitives = { path = "../genesis-liquidity/primitives", version = "0.1", default-features = false }
serai-emissions-primitives = { path = "../emissions/primitives", version = "0.1", default-features = false }
serai-in-instructions-primitives = { path = "../in-instructions/primitives", version = "0.1", default-features = false }
serai-signals-primitives = { path = "../signals/primitives", version = "0.1", default-features = false }

Expand All @@ -61,6 +62,7 @@ std = [
"serai-coins-primitives/std",
"serai-validator-sets-primitives/std",
"serai-genesis-liquidity-primitives/std",
"serai-emissions-primitives/std",
"serai-in-instructions-primitives/std",
"serai-signals-primitives/std",
]
Expand Down
1 change: 1 addition & 0 deletions substrate/abi/src/emissions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use serai_emissions_primitives as primitives;
12 changes: 8 additions & 4 deletions substrate/abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ pub mod liquidity_tokens;
pub mod dex;

pub mod validator_sets;
pub mod in_instructions;
pub mod signals;

pub mod genesis_liquidity;
pub mod emissions;

pub mod in_instructions;

pub mod signals;

pub mod babe;
pub mod grandpa;
Expand All @@ -32,8 +35,8 @@ pub enum Call {
Coins(coins::Call),
LiquidityTokens(liquidity_tokens::Call),
Dex(dex::Call),
GenesisLiquidity(genesis_liquidity::Call),
ValidatorSets(validator_sets::Call),
GenesisLiquidity(genesis_liquidity::Call),
InInstructions(in_instructions::Call),
Signals(signals::Call),
Babe(babe::Call),
Expand All @@ -54,8 +57,9 @@ pub enum Event {
Coins(coins::Event),
LiquidityTokens(liquidity_tokens::Event),
Dex(dex::Event),
GenesisLiquidity(genesis_liquidity::Event),
ValidatorSets(validator_sets::Event),
GenesisLiquidity(genesis_liquidity::Event),
Emissions,
InInstructions(in_instructions::Event),
Signals(signals::Event),
Babe,
Expand Down
23 changes: 8 additions & 15 deletions substrate/client/src/serai/dex.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use sp_core::bounded_vec::BoundedVec;
use serai_abi::primitives::{SeraiAddress, Amount, Coin};

use scale::{decode_from_bytes, Encode};

use crate::{Serai, SeraiError, TemporalSerai};
use crate::{SeraiError, TemporalSerai};

pub type DexEvent = serai_abi::dex::Event;

const PALLET: &str = "Dex";

#[derive(Clone, Copy)]
pub struct SeraiDex<'a>(pub(crate) &'a TemporalSerai<'a>);
impl<'a> SeraiDex<'a> {
Expand Down Expand Up @@ -62,17 +62,10 @@ impl<'a> SeraiDex<'a> {

/// Returns the reserves of `coin:SRI` pool.
pub async fn get_reserves(&self, coin: Coin) -> Result<Option<(Amount, Amount)>, SeraiError> {
let reserves = self
.0
.serai
.call(
"state_call",
["DexApi_get_reserves".to_string(), hex::encode((coin, Coin::Serai).encode())],
)
.await?;
let bytes = Serai::hex_decode(reserves)?;
let result = decode_from_bytes::<Option<(u64, u64)>>(bytes.into())
.map_err(|e| SeraiError::ErrorInResponse(e.to_string()))?;
Ok(result.map(|amounts| (Amount(amounts.0), Amount(amounts.1))))
self.0.runtime_api("DexApi_get_reserves", (coin, Coin::Serai)).await
}

pub async fn oracle_value(&self, coin: Coin) -> Result<Option<Amount>, SeraiError> {
self.0.storage(PALLET, "SecurityOracleValue", coin).await
}
}
4 changes: 4 additions & 0 deletions substrate/client/src/serai/genesis_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ impl<'a> SeraiGenesisLiquidity<'a> {
pub async fn supply(&self, coin: Coin) -> Result<LiquidityAmount, SeraiError> {
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(LiquidityAmount::zero()))
}

pub async fn genesis_complete_block(&self) -> Result<Option<u64>, SeraiError> {
self.0.storage(PALLET, "GenesisCompleteBlock", ()).await
}
}
33 changes: 22 additions & 11 deletions substrate/client/src/serai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,6 @@ impl Serai {
Ok(())
}

// TODO: move this into substrate/client/src/validator_sets.rs
async fn active_network_validators(&self, network: NetworkId) -> Result<Vec<Public>, SeraiError> {
let validators: String = self
.call("state_call", ["SeraiRuntimeApi_validators".to_string(), hex::encode(network.encode())])
.await?;
let bytes = Self::hex_decode(validators)?;
let r = Vec::<Public>::decode(&mut bytes.as_slice())
.map_err(|e| SeraiError::ErrorInResponse(e.to_string()))?;
Ok(r)
}

pub async fn latest_finalized_block_hash(&self) -> Result<[u8; 32], SeraiError> {
let hash: String = self.call("chain_getFinalizedHead", ()).await?;
Self::hex_decode(hash)?.try_into().map_err(|_| {
Expand Down Expand Up @@ -378,6 +367,28 @@ impl<'a> TemporalSerai<'a> {
})?))
}

async fn runtime_api<P: Encode, R: Decode>(
&self,
method: &'static str,
params: P,
) -> Result<R, SeraiError> {
let result: String = self
.serai
.call(
"state_call",
[method.to_string(), hex::encode(params.encode()), hex::encode(self.block)],
)
.await?;

let bytes = Serai::hex_decode(result.clone())?;
R::decode(&mut bytes.as_slice()).map_err(|_| {
SeraiError::InvalidRuntime(format!(
"different type than what is expected to be returned, raw value: {}",
hex::encode(result)
))
})
}

pub fn coins(&'a self) -> SeraiCoins<'a> {
SeraiCoins(self)
}
Expand Down
10 changes: 9 additions & 1 deletion substrate/client/src/serai/validator_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'a> SeraiValidatorSets<'a> {
&self,
network: NetworkId,
) -> Result<Vec<Public>, SeraiError> {
self.0.serai.active_network_validators(network).await
self.0.runtime_api("SeraiRuntimeApi_validators", network).await
}

// TODO: Store these separately since we almost never need both at once?
Expand All @@ -194,6 +194,14 @@ impl<'a> SeraiValidatorSets<'a> {
self.0.storage(PALLET, "PendingSlashReport", network).await
}

pub async fn session_begin_block(
&self,
network: NetworkId,
session: Session,
) -> Result<Option<u64>, SeraiError> {
self.0.storage(PALLET, "SessionBeginBlock", (network, session)).await
}

pub fn set_keys(
network: NetworkId,
key_pair: KeyPair,
Expand Down
Loading

0 comments on commit e098369

Please sign in to comment.