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
|
|
|
|
|
|
|
|
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;
|
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 primitives::{InInstruction, InInstructionWithBalance, SignedBatch};
|
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-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-03-31 06:34:09 -04:00
|
|
|
pub trait Config:
|
|
|
|
|
frame_system::Config<BlockNumber = u64> + 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> {
|
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
|
|
|
Batch { network: NetworkId, id: u32, block: BlockHash },
|
|
|
|
|
InstructionFailure { network: NetworkId, id: u32, index: u32 },
|
2023-01-20 11:00:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[pallet::pallet]
|
|
|
|
|
pub struct Pallet<T>(PhantomData<T>);
|
|
|
|
|
|
2023-04-16 02:57:19 -04:00
|
|
|
// The amount of batches a network has issued, which is also the ID to use for the next batch
|
2023-01-20 11:00:18 -05:00
|
|
|
#[pallet::storage]
|
2023-04-16 02:57:19 -04:00
|
|
|
#[pallet::getter(fn batches)]
|
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(crate) type Batches<T: Config> = StorageMap<_, Blake2_256, NetworkId, u32, OptionQuery>;
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-04-16 02:57:19 -04:00
|
|
|
// The latest block a network has acknowledged as finalized
|
|
|
|
|
#[pallet::storage]
|
|
|
|
|
#[pallet::getter(fn last_block)]
|
|
|
|
|
pub(crate) type LatestBlock<T: Config> =
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
let mut batch = batch.batch;
|
|
|
|
|
|
|
|
|
|
Batches::<T>::insert(batch.network, batch.id);
|
2023-04-16 02:57:19 -04:00
|
|
|
LatestBlock::<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,
|
|
|
|
|
});
|
|
|
|
|
for (i, instruction) in batch.instructions.drain(..).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,
|
|
|
|
|
_ => Err(InvalidTransaction::Call)?,
|
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-01-20 11:00:18 -05:00
|
|
|
|
2023-03-31 06:34:09 -04:00
|
|
|
// TODO: Get the latest session
|
|
|
|
|
let session = Session(0);
|
|
|
|
|
|
|
|
|
|
let mut set = ValidatorSet { session, network };
|
|
|
|
|
// TODO: If this session just set their keys, it'll invalidate anything in the mempool
|
|
|
|
|
// Should there be a transitory period/future-set cut off?
|
|
|
|
|
let key = if let Some(keys) = ValidatorSets::<T>::keys(set) {
|
|
|
|
|
keys.0
|
|
|
|
|
} else {
|
|
|
|
|
// If this set hasn't set their keys yet, use the previous set's
|
|
|
|
|
if set.session.0 == 0 {
|
|
|
|
|
Err(InvalidTransaction::BadProof)?;
|
|
|
|
|
}
|
|
|
|
|
set.session.0 -= 1;
|
|
|
|
|
|
|
|
|
|
if let Some(keys) = ValidatorSets::<T>::keys(set) {
|
|
|
|
|
keys.0
|
|
|
|
|
} else {
|
|
|
|
|
Err(InvalidTransaction::BadProof)?
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-01-20 11:00:18 -05:00
|
|
|
|
2023-03-31 06:34:09 -04:00
|
|
|
if !key.verify(&batch.batch.encode(), &batch.signature) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// Verify the batch is sequential
|
|
|
|
|
// Batches has the last ID set. The next ID should be it + 1
|
|
|
|
|
// If there's no ID, the next ID should be 0
|
|
|
|
|
let expected = Batches::<T>::get(network).map(|prev| prev + 1).unwrap_or(0);
|
|
|
|
|
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::*;
|