2023-01-20 11:00:18 -05:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
|
|
2023-03-26 08:43:01 -04:00
|
|
|
use scale::Encode;
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-09-29 03:51:01 -04:00
|
|
|
use sp_io::hashing::blake2_256;
|
2023-01-20 11:00:18 -05:00
|
|
|
use sp_runtime::RuntimeDebug;
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
use serai_primitives::{BlockHash, NetworkId};
|
2023-01-20 11:00:18 -05:00
|
|
|
|
|
|
|
|
pub use in_instructions_primitives as primitives;
|
2023-05-13 04:20:13 -04:00
|
|
|
use primitives::*;
|
2023-01-20 11:00:18 -05:00
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Encode, RuntimeDebug)]
|
2023-03-26 08:43:01 -04:00
|
|
|
#[cfg_attr(feature = "std", derive(scale::Decode, thiserror::Error))]
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
pub enum PalletError {
|
|
|
|
|
#[cfg_attr(feature = "std", error("batch for unrecognized network"))]
|
|
|
|
|
UnrecognizedNetwork,
|
|
|
|
|
#[cfg_attr(feature = "std", error("invalid signature for batch"))]
|
|
|
|
|
InvalidSignature,
|
2023-01-20 11:00:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[frame_support::pallet]
|
|
|
|
|
pub mod pallet {
|
2023-03-31 06:34:09 -04:00
|
|
|
use sp_application_crypto::RuntimePublic;
|
2023-08-14 18:57:38 +03:00
|
|
|
use sp_runtime::traits::Zero;
|
|
|
|
|
use sp_core::sr25519::Public;
|
2023-03-31 06:34:09 -04:00
|
|
|
|
2023-01-20 11:00:18 -05:00
|
|
|
use frame_support::pallet_prelude::*;
|
|
|
|
|
use frame_system::pallet_prelude::*;
|
|
|
|
|
|
2023-01-28 01:47:13 -05:00
|
|
|
use tokens_pallet::{Config as TokensConfig, Pallet as Tokens};
|
2023-03-31 06:34:09 -04:00
|
|
|
use validator_sets_pallet::{
|
|
|
|
|
primitives::{Session, ValidatorSet},
|
|
|
|
|
Config as ValidatorSetsConfig, Pallet as ValidatorSets,
|
|
|
|
|
};
|
2023-01-28 01:47:13 -05:00
|
|
|
|
2023-01-20 11:00:18 -05:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[pallet::config]
|
2023-07-18 22:30:55 -04:00
|
|
|
pub trait Config: frame_system::Config + ValidatorSetsConfig + TokensConfig {
|
2023-01-20 11:00:18 -05:00
|
|
|
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[pallet::event]
|
|
|
|
|
#[pallet::generate_deposit(fn deposit_event)]
|
|
|
|
|
pub enum Event<T: Config> {
|
2023-09-29 03:51:01 -04:00
|
|
|
Batch { network: NetworkId, id: u32, block: BlockHash, instructions_hash: [u8; 32] },
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
InstructionFailure { network: NetworkId, id: u32, index: u32 },
|
2023-01-20 11:00:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[pallet::pallet]
|
|
|
|
|
pub struct Pallet<T>(PhantomData<T>);
|
|
|
|
|
|
2023-08-26 21:36:13 -04:00
|
|
|
// The ID of the last executed Batch for a network.
|
2023-01-20 11:00:18 -05:00
|
|
|
#[pallet::storage]
|
2023-04-16 02:57:19 -04:00
|
|
|
#[pallet::getter(fn batches)]
|
2023-08-26 21:36:13 -04:00
|
|
|
pub(crate) type LastBatch<T: Config> = StorageMap<_, Blake2_256, NetworkId, u32, OptionQuery>;
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-08-14 18:57:38 +03:00
|
|
|
// The last Serai block in which this validator set included a batch
|
|
|
|
|
#[pallet::storage]
|
|
|
|
|
#[pallet::getter(fn last_batch_block)]
|
|
|
|
|
pub(crate) type LastBatchBlock<T: Config> =
|
|
|
|
|
StorageMap<_, Blake2_256, NetworkId, BlockNumberFor<T>, OptionQuery>;
|
|
|
|
|
|
2023-04-16 02:57:19 -04:00
|
|
|
// The latest block a network has acknowledged as finalized
|
|
|
|
|
#[pallet::storage]
|
2023-08-14 18:57:38 +03:00
|
|
|
#[pallet::getter(fn latest_network_block)]
|
|
|
|
|
pub(crate) type LatestNetworkBlock<T: Config> =
|
2023-04-16 02:57:19 -04:00
|
|
|
StorageMap<_, Blake2_256, NetworkId, BlockHash, OptionQuery>;
|
|
|
|
|
|
2023-01-28 01:47:13 -05:00
|
|
|
impl<T: Config> Pallet<T> {
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> {
|
|
|
|
|
match instruction.instruction {
|
|
|
|
|
InInstruction::Transfer(address) => Tokens::<T>::mint(address, instruction.balance),
|
2023-01-28 01:47:13 -05:00
|
|
|
_ => panic!("unsupported instruction"),
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 23:55:59 -04:00
|
|
|
fn key_for_network<T: Config>(network: NetworkId) -> Result<(Session, Option<Public>, Option<Public>), InvalidTransaction> {
|
|
|
|
|
let session = ValidatorSets::<T>::session(network);
|
2023-08-14 18:57:38 +03:00
|
|
|
let mut set = ValidatorSet { session, network };
|
2023-10-10 23:55:59 -04:00
|
|
|
let latest = ValidatorSets::<T>::keys(set).map(|keys| keys.0);
|
|
|
|
|
let prior = if set.session.0 != 0 {
|
2023-08-14 18:57:38 +03:00
|
|
|
set.session.0 -= 1;
|
2023-10-10 23:55:59 -04:00
|
|
|
ValidatorSets::<T>::keys(set).map(|keys| keys.0)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
// If there's no keys set, then this must be an invalid signature
|
|
|
|
|
if prior.is_none() && latest.is_none() {
|
|
|
|
|
Err(InvalidTransaction::BadProof)?;
|
2023-08-14 18:57:38 +03:00
|
|
|
}
|
2023-10-10 23:55:59 -04:00
|
|
|
Ok((session, prior, latest))
|
2023-08-14 18:57:38 +03:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 11:00:18 -05:00
|
|
|
#[pallet::call]
|
|
|
|
|
impl<T: Config> Pallet<T> {
|
|
|
|
|
#[pallet::call_index(0)]
|
2023-01-28 01:47:13 -05:00
|
|
|
#[pallet::weight((0, DispatchClass::Operational))] // TODO
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
pub fn execute_batch(origin: OriginFor<T>, batch: SignedBatch) -> DispatchResult {
|
2023-01-20 11:00:18 -05:00
|
|
|
ensure_none(origin)?;
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
|
2023-08-14 18:57:38 +03:00
|
|
|
let batch = batch.batch;
|
|
|
|
|
|
|
|
|
|
// TODO: Test validate_unsigned is actually called prior to execution, which is required for
|
|
|
|
|
// this to be safe
|
|
|
|
|
LastBatchBlock::<T>::insert(batch.network, frame_system::Pallet::<T>::block_number());
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
|
2023-08-26 21:36:13 -04:00
|
|
|
LastBatch::<T>::insert(batch.network, batch.id);
|
2023-08-14 18:57:38 +03:00
|
|
|
LatestNetworkBlock::<T>::insert(batch.network, batch.block);
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
Self::deposit_event(Event::Batch {
|
|
|
|
|
network: batch.network,
|
|
|
|
|
id: batch.id,
|
|
|
|
|
block: batch.block,
|
2023-09-29 03:51:01 -04:00
|
|
|
instructions_hash: blake2_256(&batch.instructions.encode()),
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
});
|
2023-08-14 18:57:38 +03:00
|
|
|
for (i, instruction) in batch.instructions.into_iter().enumerate() {
|
2023-04-10 12:48:48 -04:00
|
|
|
// TODO: Check this balance's coin belongs to this network
|
|
|
|
|
// If they don't, the validator set should be completely slashed, without question
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
if Self::execute(instruction).is_err() {
|
|
|
|
|
Self::deposit_event(Event::InstructionFailure {
|
|
|
|
|
network: batch.network,
|
|
|
|
|
id: batch.id,
|
|
|
|
|
index: u32::try_from(i).unwrap(),
|
|
|
|
|
});
|
2023-01-20 11:00:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
#[pallet::validate_unsigned]
|
|
|
|
|
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
2023-01-20 11:00:18 -05:00
|
|
|
type Call = Call<T>;
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
fn validate_unsigned(_: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
2023-01-20 11:00:18 -05:00
|
|
|
// Match to be exhaustive
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
let batch = match call {
|
|
|
|
|
Call::execute_batch { ref batch } => batch,
|
2023-05-13 02:02:47 -04:00
|
|
|
Call::__Ignore(_, _) => unreachable!(),
|
2023-01-20 11:00:18 -05:00
|
|
|
};
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
let network = batch.batch.network;
|
2023-10-10 23:55:59 -04:00
|
|
|
let (current_session, prior, current) = key_for_network::<T>(network)?;
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-08-14 18:57:38 +03:00
|
|
|
// verify the batch size
|
|
|
|
|
// TODO: Merge this encode with the one done by batch_message
|
|
|
|
|
if batch.batch.encode().len() > MAX_BATCH_SIZE {
|
|
|
|
|
Err(InvalidTransaction::ExhaustsResources)?;
|
|
|
|
|
}
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-08-14 18:57:38 +03:00
|
|
|
// verify the signature
|
2023-10-10 23:55:59 -04:00
|
|
|
let batch_message = batch_message(&batch.batch);
|
|
|
|
|
// Check the prior key first since only a single `Batch` (the last one) will be when prior is
|
|
|
|
|
// Some yet prior wasn't the signing key
|
|
|
|
|
let valid_by_prior = if let Some(key) = prior {
|
|
|
|
|
key.verify(&batch_message, &batch.signature)
|
|
|
|
|
} else { false };
|
|
|
|
|
let valid = valid_by_prior || (if let Some(key) = current {
|
|
|
|
|
key.verify(&batch_message, &batch.signature)
|
|
|
|
|
} else { false });
|
|
|
|
|
if !valid {
|
2023-03-31 06:34:09 -04:00
|
|
|
Err(InvalidTransaction::BadProof)?;
|
|
|
|
|
}
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
|
2023-10-10 23:55:59 -04:00
|
|
|
// If it wasn't valid by the prior key, meaning it was valid by the current key, the current
|
|
|
|
|
// 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_session(network, Session(current_session.0 - 1));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 18:57:38 +03:00
|
|
|
// check that this validator set isn't publishing a batch more than once per block
|
|
|
|
|
let current_block = <frame_system::Pallet<T>>::block_number();
|
|
|
|
|
let last_block = LastBatchBlock::<T>::get(network).unwrap_or(Zero::zero());
|
|
|
|
|
if last_block >= current_block {
|
|
|
|
|
Err(InvalidTransaction::Future)?;
|
|
|
|
|
}
|
|
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
// Verify the batch is sequential
|
2023-08-26 21:36:13 -04:00
|
|
|
// LastBatch has the last ID set. The next ID should be it + 1
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
// If there's no ID, the next ID should be 0
|
2023-08-26 21:36:13 -04:00
|
|
|
let expected = LastBatch::<T>::get(network).map_or(0, |prev| prev + 1);
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
if batch.batch.id < expected {
|
|
|
|
|
Err(InvalidTransaction::Stale)?;
|
|
|
|
|
}
|
|
|
|
|
if batch.batch.id > expected {
|
|
|
|
|
Err(InvalidTransaction::Future)?;
|
|
|
|
|
}
|
2023-01-20 11:00:18 -05:00
|
|
|
|
Move in instructions from inherent transactions to unsigned transactions
The original intent was to use inherent transactions to prevent needing to vote
on-chain, which would spam the chain with worthless votes. Inherent
transactions, and our Tendermint library, would use the BFT's processs voting
to also vote on all included transactions. This perfectly collapses integrity
voting creating *no additional on-chain costs*.
Unfortunately, this led to issues such as #6, along with questions of validator
scalability when all validators are expencted to participate in consensus (in
order to vote on if the included instructions are valid). This has been
summarized in #241.
With this change, we can remove Tendermint from Substrate. This greatly
decreases our complexity. While I'm unhappy with the amount of time spent on
it, just to reach this conclusion, thankfully tendermint-machine itself is
still usable for #163. This also has reached a tipping point recently as the
polkadot-v0.9.40 branch of substrate changed how syncing works, requiring
further changes to sc-tendermint. These have no value if we're just going to
get rid of it later, due to fundamental design issues, yet I would like to
keep Substrate updated.
This should be followed by moving back to GRANDPA, enabling closing most open
Tendermint issues.
Please note the current in-instructions-pallet does not actually verify the
included signature yet. It's marked TODO, despite this bing critical.
2023-03-26 02:58:04 -04:00
|
|
|
ValidTransaction::with_tag_prefix("in-instructions")
|
|
|
|
|
.and_provides((batch.batch.network, batch.batch.id))
|
|
|
|
|
// Set a 10 block longevity, though this should be included in the next block
|
|
|
|
|
.longevity(10)
|
|
|
|
|
.propagate(true)
|
|
|
|
|
.build()
|
2023-01-20 11:00:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub use pallet::*;
|