use current header version in new slates (#804)

* use current header version

* flip header version check and bump min node version
This commit is contained in:
wiesche
2026-09-15 19:42:56 +02:00
committed by GitHub
parent e5e319b47e
commit 991ba1a1f7
6 changed files with 32 additions and 25 deletions
+1 -1
View File
@@ -973,7 +973,7 @@ pub trait OwnerRpc {
"id": "0436430c-2b02-624c-2032-570501212b00",
"sigs": [],
"sta": "S3",
"ver": "4:3"
"ver": "4:5"
}
}
}
+3 -7
View File
@@ -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 -1
View File
@@ -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);
+2 -13
View File
@@ -18,8 +18,7 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::Cursor;
use uuid::Uuid;
use crate::grin_core::consensus::valid_header_version;
use crate::grin_core::core::HeaderVersion;
use crate::grin_core::consensus::header_version;
use crate::grin_keychain::{Identifier, Keychain};
use crate::grin_util::secp::key::SecretKey;
use crate::grin_util::secp::pedersen;
@@ -70,17 +69,7 @@ where
}
slate.amount = amount;
if valid_header_version(current_height, HeaderVersion(1)) {
slate.version_info.block_header_version = 1;
}
if valid_header_version(current_height, HeaderVersion(2)) {
slate.version_info.block_header_version = 2;
}
if valid_header_version(current_height, HeaderVersion(3)) {
slate.version_info.block_header_version = 3;
}
slate.version_info.block_header_version = header_version(current_height).0;
// Set the features explicitly to 0 here.
// This will generate a Plain kernel (rather than a HeightLocked kernel).
+2 -2
View File
@@ -34,8 +34,8 @@ pub mod v4_bin;
/// The most recent version of the slate
pub const CURRENT_SLATE_VERSION: u16 = 4;
/// The grin block header this slate is intended to be compatible with
pub const GRIN_BLOCK_HEADER_VERSION: u16 = 3;
/// The latest grin block header version this wallet supports
pub const GRIN_BLOCK_HEADER_VERSION: u16 = 5;
/// Existing versions of the slate
#[derive(EnumIter, Serialize, Deserialize, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
+1 -1
View File
@@ -20,7 +20,7 @@ use semver::Version;
use std::thread;
use std::time::Duration;
const MIN_COMPAT_NODE_VERSION: &str = "4.0.0-alpha.1";
const MIN_COMPAT_NODE_VERSION: &str = "5.0.0-beta.1";
pub fn wallet_command<C>(
wallet_args: &ArgMatches<'_>,