mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-15 11:53:54 +01:00
use current header version in new slates (#804)
* use current header version
* flip header version check and bump min node version
(cherry picked from commit 991ba1a1f7)
This commit is contained in:
@@ -66,22 +66,18 @@ lazy_static! {
|
||||
|
||||
fn check_middleware(
|
||||
name: ForeignCheckMiddlewareFn,
|
||||
node_version_info: Option<NodeVersionInfo>,
|
||||
_node_version_info: Option<NodeVersionInfo>,
|
||||
slate: Option<&Slate>,
|
||||
) -> Result<(), Error> {
|
||||
match name {
|
||||
// allow coinbases to be built regardless
|
||||
ForeignCheckMiddlewareFn::BuildCoinbase => Ok(()),
|
||||
_ => {
|
||||
let mut bhv = 3;
|
||||
if let Some(n) = node_version_info {
|
||||
bhv = n.block_header_version;
|
||||
}
|
||||
if let Some(s) = slate {
|
||||
if bhv > 4 && s.version_info.block_header_version < GRIN_BLOCK_HEADER_VERSION {
|
||||
if s.version_info.block_header_version > GRIN_BLOCK_HEADER_VERSION {
|
||||
Err(Error::Compatibility(
|
||||
"Incoming Slate is not compatible with this wallet. \
|
||||
Please upgrade the node or use a different one."
|
||||
Please upgrade the wallet."
|
||||
.into(),
|
||||
))?;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use grin_core as core;
|
||||
use self::core::core::transaction;
|
||||
use self::core::core::Transaction;
|
||||
use self::core::global;
|
||||
use self::libwallet::{InitTxArgs, OutputStatus, Slate, SlateState};
|
||||
use self::libwallet::{InitTxArgs, OutputStatus, Slate, SlateState, GRIN_BLOCK_HEADER_VERSION};
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use std::convert::TryInto;
|
||||
use std::path::PathBuf;
|
||||
@@ -105,6 +105,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
// assert wallet contents
|
||||
// and a single use api for a send command
|
||||
let amount = 60_000_000_000;
|
||||
let header_version = core::consensus::header_version(chain.head().unwrap().height).0;
|
||||
let mut slate = Slate::blank(1, false);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
@@ -124,6 +125,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
|
||||
assert_eq!(slate_i.state, SlateState::Standard1);
|
||||
assert_eq!(slate_i.version_info.block_header_version, header_version);
|
||||
|
||||
// Check we are creating a tx with the expected lock_height of 0.
|
||||
// We will check this produces a Plain kernel later.
|
||||
@@ -131,6 +133,26 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
// wallet2 already has this slate, so accepted versions fail on the duplicate check
|
||||
for bhv in 1..=GRIN_BLOCK_HEADER_VERSION + 1 {
|
||||
let mut s = slate_i.clone();
|
||||
s.version_info.block_header_version = bhv;
|
||||
let res = wallet::controller::foreign_single_use(
|
||||
wallet2.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask2_i.clone(),
|
||||
|api| api.receive_tx(&s, None, None).map(|_| ()),
|
||||
);
|
||||
if bhv <= GRIN_BLOCK_HEADER_VERSION {
|
||||
assert!(matches!(
|
||||
res,
|
||||
Err(libwallet::Error::TransactionAlreadyReceived(_))
|
||||
));
|
||||
} else {
|
||||
assert!(matches!(res, Err(libwallet::Error::Compatibility(_))));
|
||||
}
|
||||
}
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
|
||||
Reference in New Issue
Block a user