Skip to content

Commit

Permalink
address review: add layer1 to Genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Jan 16, 2025
1 parent 6cd46eb commit acb131d
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 188 deletions.
4 changes: 3 additions & 1 deletion src/operation/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use strict_encoding::StrictDumb;
use crate::{
impl_serde_baid64, Assign, AssignmentType, Assignments, BundleId, ConcealedAttach,
ConcealedData, ConcealedState, ConfidentialState, DataState, ExposedSeal, ExposedState,
Extension, ExtensionType, Ffv, Genesis, GlobalState, GlobalStateType, Operation,
Extension, ExtensionType, Ffv, Genesis, GlobalState, GlobalStateType, Layer1, Operation,
PedersenCommitment, Redeemed, SchemaId, SecretSeal, Transition, TransitionBundle,
TransitionType, TypedAssigns, XChain, LIB_NAME_RGB_COMMIT,
};
Expand Down Expand Up @@ -237,6 +237,7 @@ pub struct BaseCommitment {
pub schema_id: SchemaId,
pub timestamp: i64,
pub issuer: StrictHash,
pub layer1: Layer1,
pub testnet: bool,
pub close_method: CloseMethod,
pub asset_tags: StrictHash,
Expand Down Expand Up @@ -281,6 +282,7 @@ impl Genesis {
flags: self.flags,
schema_id: self.schema_id,
timestamp: self.timestamp,
layer1: self.layer1,
testnet: self.testnet,
close_method: self.close_method,
issuer: self.issuer.commit_id(),
Expand Down
14 changes: 1 addition & 13 deletions src/operation/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ pub struct Genesis {
pub flags: ReservedBytes<1, 0>,
pub timestamp: i64,
pub issuer: Identity,
pub layer1: Layer1,
pub testnet: bool,
pub close_method: CloseMethod,
pub asset_tags: AssetTags,
Expand All @@ -373,19 +374,6 @@ pub struct Genesis {
impl StrictSerialize for Genesis {}
impl StrictDeserialize for Genesis {}

impl Genesis {
pub fn layer1(&self) -> Option<Layer1> {
if let Some((_, typed_assigns)) = self.assignments.iter().next() {
typed_assigns
.to_confidential_seals()
.first()
.map(|cs| cs.layer1())
} else {
None
}
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT)]
Expand Down
5 changes: 3 additions & 2 deletions src/operation/xchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ pub const XCHAIN_LIQUID_PREFIX: &str = "lq";

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
#[display(lowercase)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_COMMIT, tags = repr, into_u8, try_from_u8)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
#[repr(u8)]
#[derive(Default)]
pub enum Layer1 {
#[strict_type(dumb)]
#[default]
Bitcoin = 0,
Liquid = 1,
}
Expand Down
5 changes: 2 additions & 3 deletions src/validation/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ pub enum Failure {
SealNoPubWitness(BundleId, XWitnessId, WitnessResolverError),
/// witness layer 1 {anchor} doesn't match seal definition {seal}.
SealWitnessLayer1Mismatch { seal: Layer1, anchor: Layer1 },
/// seal {1} is defined on {0} which is not in the set of layers allowed
/// by the contract genesis.
SealLayerMismatch(Layer1, XGraphSeal),
/// seal {0} is defined on {1} which is not the layer 1 defined by the contract genesis ({2}).
SealLayerMismatch(XGraphSeal, Layer1, Layer1),
/// transition bundle {0} doesn't close seal with the witness {1}. Details:
/// {2}
SealsInvalid(BundleId, XWitnessId, String),
Expand Down
9 changes: 4 additions & 5 deletions src/validation/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct Validator<

schema_id: SchemaId,
contract_id: ContractId,
layer1: Option<Layer1>,
layer1: Layer1,
close_method: CloseMethod,

contract_state: Rc<RefCell<S>>,
Expand Down Expand Up @@ -162,14 +162,13 @@ impl<
let genesis = consignment.genesis();
let contract_id = genesis.contract_id();
let schema_id = genesis.schema_id;
let layer1 = genesis.layer1;
let close_method = genesis.close_method;

// Prevent repeated validation of single-use seals
let validated_op_seals = RefCell::new(BTreeSet::<OpId>::new());
let input_transitions = RefCell::new(BTreeSet::<Opout>::new());

let layer1 = genesis.layer1();

Self {
consignment,
status: RefCell::new(status),
Expand Down Expand Up @@ -601,10 +600,10 @@ impl<
});
continue;
}
if self.layer1 != Some(seal.layer1()) {
if self.layer1 != seal.layer1() {
self.status
.borrow_mut()
.add_failure(Failure::SealLayerMismatch(seal.layer1(), seal));
.add_failure(Failure::SealLayerMismatch(seal, seal.layer1(), self.layer1));
continue;
}

Expand Down
Loading

0 comments on commit acb131d

Please sign in to comment.