Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support contract state computation during validation #244

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/containers/partials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl Batch {

pub fn set_priority(&mut self, priority: u8) {
self.main.transition.nonce = priority;
for mut info in &mut self.blanks {
for info in &mut self.blanks {
info.transition.nonce = priority;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod merge_reveal;
pub use assignments::{KnownState, OutputAssignment, TypedAssignsExt};
pub use bundle::{BundleExt, RevealError};
pub use merge_reveal::{MergeReveal, MergeRevealError};
use rgb::vm::AnchoredOpRef;
use rgb::vm::OrdOpRef;
use rgb::{OpId, XWitnessId};

use crate::LIB_NAME_RGB_STD;
Expand All @@ -46,12 +46,12 @@ pub enum OpWitness {
Extension(XWitnessId),
}

impl From<AnchoredOpRef<'_>> for OpWitness {
fn from(aor: AnchoredOpRef) -> Self {
impl From<OrdOpRef<'_>> for OpWitness {
fn from(aor: OrdOpRef) -> Self {
match aor {
AnchoredOpRef::Genesis(_) => OpWitness::Genesis,
AnchoredOpRef::Transition(_, witness_id) => OpWitness::Transition(witness_id),
AnchoredOpRef::Extension(_, witness_id) => OpWitness::Transition(witness_id),
OrdOpRef::Genesis(_) => OpWitness::Genesis,
OrdOpRef::Transition(_, witness_id, ..) => OpWitness::Transition(witness_id),
OrdOpRef::Extension(_, witness_id, ..) => OpWitness::Transition(witness_id),
}
}
}
Expand Down
28 changes: 10 additions & 18 deletions src/persistence/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use bp::dbc::tapret::TapretCommitment;
use commit_verify::{CommitId, Conceal};
use rgb::validation::ResolveWitness;
use rgb::vm::{
AnchoredOpRef, ContractStateAccess, ContractStateEvolve, GlobalContractState, GlobalOrd,
GlobalStateIter, UnknownGlobalStateType, WitnessOrd,
ContractStateAccess, ContractStateEvolve, GlobalContractState, GlobalOrd, GlobalStateIter,
OrdOpRef, UnknownGlobalStateType, WitnessOrd,
};
use rgb::{
Assign, AssignmentType, Assignments, AssignmentsRef, AttachId, AttachState, BundleId,
Expand Down Expand Up @@ -667,7 +667,7 @@ impl MemContractState {
}
}

fn add_operation(&mut self, op: AnchoredOpRef) {
fn add_operation(&mut self, op: OrdOpRef) {
let opid = op.id();

for (ty, state) in op.globals() {
Expand Down Expand Up @@ -956,13 +956,7 @@ impl ContractStateEvolve for MemContract<MemContractState> {
}
}

fn evolve_state(&mut self, op: AnchoredOpRef) -> Result<(), confinement::Error> {
fn ordering(
filter: &HashMap<XWitnessId, WitnessOrd>,
witness_id: XWitnessId,
) -> WitnessOrd {
*filter.get(&witness_id).expect("unknown witness id")
}
fn evolve_state(&mut self, op: OrdOpRef) -> Result<(), confinement::Error> {
(move || -> Result<(), SerializeError> {
fn writer(me: &mut MemContract<MemContractState>) -> MemContractWriter {
MemContractWriter {
Expand All @@ -979,17 +973,15 @@ impl ContractStateEvolve for MemContract<MemContractState> {
}
}
match op {
AnchoredOpRef::Genesis(genesis) => {
OrdOpRef::Genesis(genesis) => {
let mut writer = writer(self);
writer.add_genesis(genesis)
}
AnchoredOpRef::Transition(transition, witness_id) => {
let ord = ordering(&self.filter, witness_id);
OrdOpRef::Transition(transition, witness_id, ord) => {
let mut writer = writer(self);
writer.add_transition(transition, witness_id, ord)
}
AnchoredOpRef::Extension(extension, witness_id) => {
let ord = ordering(&self.filter, witness_id);
OrdOpRef::Extension(extension, witness_id, ord) => {
let mut writer = writer(self);
writer.add_extension(extension, witness_id, ord)
}
Expand Down Expand Up @@ -1062,7 +1054,7 @@ impl<'mem> ContractStateWrite for MemContractWriter<'mem> {
/// If genesis violates RGB consensus rules and wasn't checked against the
/// schema before adding to the history.
fn add_genesis(&mut self, genesis: &Genesis) -> Result<(), Self::Error> {
self.contract.add_operation(AnchoredOpRef::Genesis(genesis));
self.contract.add_operation(OrdOpRef::Genesis(genesis));
Ok(())
}

Expand All @@ -1078,7 +1070,7 @@ impl<'mem> ContractStateWrite for MemContractWriter<'mem> {
) -> Result<(), Self::Error> {
(self.writer)(witness_id, ord)?;
self.contract
.add_operation(AnchoredOpRef::Transition(transition, witness_id));
.add_operation(OrdOpRef::Transition(transition, witness_id, ord));
Ok(())
}

Expand All @@ -1094,7 +1086,7 @@ impl<'mem> ContractStateWrite for MemContractWriter<'mem> {
) -> Result<(), Self::Error> {
(self.writer)(witness_id, ord)?;
self.contract
.add_operation(AnchoredOpRef::Extension(extension, witness_id));
.add_operation(OrdOpRef::Extension(extension, witness_id, ord));
Ok(())
}
}
Expand Down
Loading