2023-01-28 06:47:13 +00:00
|
|
|
use rand_core::{RngCore, OsRng};
|
|
|
|
|
2023-09-29 07:51:01 +00:00
|
|
|
use blake2::{
|
|
|
|
digest::{consts::U32, Digest},
|
|
|
|
Blake2b,
|
|
|
|
};
|
|
|
|
|
|
|
|
use scale::Encode;
|
|
|
|
|
2023-10-19 10:22:21 +00:00
|
|
|
use serai_runtime::coins::primitives::OutInstructionWithBalance;
|
2023-03-31 10:34:09 +00:00
|
|
|
use sp_core::Pair;
|
2023-01-28 06:47:13 +00:00
|
|
|
|
|
|
|
use serai_client::{
|
2023-03-31 10:34:09 +00:00
|
|
|
subxt::config::extrinsic_params::BaseExtrinsicParamsBuilder,
|
2023-01-28 06:47:13 +00:00
|
|
|
primitives::{
|
2023-04-18 06:01:53 +00:00
|
|
|
Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress, Data, ExternalAddress,
|
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 06:58:04 +00:00
|
|
|
insecure_pair_from_name,
|
|
|
|
},
|
|
|
|
in_instructions::{
|
|
|
|
InInstructionsEvent,
|
2023-03-31 12:11:23 +00:00
|
|
|
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
2023-01-28 06:47:13 +00:00
|
|
|
},
|
2023-10-19 10:22:21 +00:00
|
|
|
coins::{primitives::OutInstruction, CoinsEvent},
|
2023-10-14 06:47:58 +00:00
|
|
|
PairSigner, Serai, SeraiCoins,
|
2023-01-28 06:47:13 +00:00
|
|
|
};
|
|
|
|
|
2023-03-31 10:34:09 +00:00
|
|
|
mod common;
|
2023-03-31 12:11:23 +00:00
|
|
|
use common::{serai, tx::publish_tx, in_instructions::provide_batch};
|
2023-01-28 06:47:13 +00:00
|
|
|
|
|
|
|
serai_test!(
|
|
|
|
async fn burn() {
|
2023-04-18 06:01:53 +00:00
|
|
|
let network = NetworkId::Bitcoin;
|
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 06:58:04 +00:00
|
|
|
let id = 0;
|
|
|
|
|
|
|
|
let mut block_hash = BlockHash([0; 32]);
|
|
|
|
OsRng.fill_bytes(&mut block_hash.0);
|
2023-01-28 06:47:13 +00:00
|
|
|
|
2023-03-31 10:34:09 +00:00
|
|
|
let pair = insecure_pair_from_name("Dave");
|
2023-01-28 06:47:13 +00:00
|
|
|
let public = pair.public();
|
|
|
|
let address = SeraiAddress::from(public);
|
|
|
|
|
2023-04-18 06:01:53 +00:00
|
|
|
let coin = Coin::Bitcoin;
|
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 06:58:04 +00:00
|
|
|
let amount = Amount(OsRng.next_u64().saturating_add(1));
|
2023-01-28 06:47:13 +00:00
|
|
|
let balance = Balance { coin, amount };
|
|
|
|
|
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 06:58:04 +00:00
|
|
|
let batch = Batch {
|
|
|
|
network,
|
|
|
|
id,
|
|
|
|
block: block_hash,
|
|
|
|
instructions: vec![InInstructionWithBalance {
|
|
|
|
instruction: InInstruction::Transfer(address),
|
|
|
|
balance,
|
|
|
|
}],
|
|
|
|
};
|
2023-03-31 10:34:09 +00:00
|
|
|
|
2023-09-29 07:51:01 +00:00
|
|
|
let block = provide_batch(batch.clone()).await;
|
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 06:58:04 +00:00
|
|
|
|
2023-03-31 10:34:09 +00:00
|
|
|
let serai = serai().await;
|
2023-10-14 06:47:58 +00:00
|
|
|
let serai = serai.as_of(block);
|
|
|
|
let batches = serai.in_instructions().batch_events().await.unwrap();
|
2023-09-29 07:51:01 +00:00
|
|
|
assert_eq!(
|
|
|
|
batches,
|
|
|
|
vec![InInstructionsEvent::Batch {
|
|
|
|
network,
|
|
|
|
id,
|
|
|
|
block: block_hash,
|
|
|
|
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
|
|
|
}]
|
|
|
|
);
|
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 06:58:04 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
2023-10-14 06:47:58 +00:00
|
|
|
serai.coins().mint_events().await.unwrap(),
|
2023-10-19 10:30:58 +00:00
|
|
|
vec![CoinsEvent::Mint { to: address.into(), balance }]
|
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 06:58:04 +00:00
|
|
|
);
|
2023-10-19 10:22:21 +00:00
|
|
|
assert_eq!(serai.coins().coin_supply(coin).await.unwrap(), amount);
|
|
|
|
assert_eq!(serai.coins().coin_balance(coin, address).await.unwrap(), amount);
|
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 06:58:04 +00:00
|
|
|
|
|
|
|
// Now burn it
|
2023-01-28 06:47:13 +00:00
|
|
|
let mut rand_bytes = vec![0; 32];
|
|
|
|
OsRng.fill_bytes(&mut rand_bytes);
|
|
|
|
let external_address = ExternalAddress::new(rand_bytes).unwrap();
|
|
|
|
|
|
|
|
let mut rand_bytes = vec![0; 32];
|
|
|
|
OsRng.fill_bytes(&mut rand_bytes);
|
|
|
|
let data = Data::new(rand_bytes).unwrap();
|
|
|
|
|
2023-10-19 10:22:21 +00:00
|
|
|
let instruction = OutInstructionWithBalance {
|
|
|
|
balance,
|
|
|
|
instruction: OutInstruction { address: external_address, data: Some(data) },
|
|
|
|
};
|
2023-10-14 06:47:58 +00:00
|
|
|
let serai = serai.into_inner();
|
2023-03-31 00:24:11 +00:00
|
|
|
let block = publish_tx(
|
2023-03-31 10:34:09 +00:00
|
|
|
&serai
|
|
|
|
.sign(
|
|
|
|
&PairSigner::new(pair),
|
2023-10-19 10:22:21 +00:00
|
|
|
&SeraiCoins::burn(instruction.clone()),
|
2023-03-31 10:34:09 +00:00
|
|
|
0,
|
|
|
|
BaseExtrinsicParamsBuilder::new(),
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2023-03-31 00:24:11 +00:00
|
|
|
)
|
|
|
|
.await;
|
|
|
|
|
2023-10-14 06:47:58 +00:00
|
|
|
let serai = serai.as_of(block).coins();
|
|
|
|
let events = serai.burn_events().await.unwrap();
|
2023-10-19 10:30:58 +00:00
|
|
|
assert_eq!(events, vec![CoinsEvent::Burn { from: address.into(), instruction }]);
|
2023-10-19 10:22:21 +00:00
|
|
|
assert_eq!(serai.coin_supply(coin).await.unwrap(), Amount(0));
|
|
|
|
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
|
2023-01-28 06:47:13 +00:00
|
|
|
}
|
|
|
|
);
|