Skip to content

Commit

Permalink
vm: use operation type in ordering
Browse files Browse the repository at this point in the history
If we have two different state transitions of different mined into the same block, which (by mistake) have the same nonce, we still can order them using type. This allows usage of type id value as a way of setting strong ordering overriding nonce values (for instance token issues can be always ordered before spendings)
  • Loading branch information
dr-orlovsky committed Aug 22, 2024
1 parent 14d07f5 commit d465448
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const LIB_ID_RGB_COMMIT: &str =
"stl:ZMTVCU25-QDo98xR-wI91wcu-ydb7kui-QfZbF$n-0KDS2ow#tuna-safari-design";
/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_LOGIC: &str =
"stl:LpE2Q!Jf-pKsvjM$-ntKgUld-!zeRRa!-v7l6pzJ-qW2YceY#africa-choice-biology";
"stl:bioTBozT-NqelHGE-SPbnpMA-XBNSbXZ-6X0dANE-WHVirL8#explain-marvin-bless";

Check warning on line 43 in src/stl.rs

View workflow job for this annotation

GitHub Actions / typos

"HGE" should be "HE".

Check warning on line 43 in src/stl.rs

View workflow job for this annotation

GitHub Actions / typos

"ANE" should be "AND".

fn _rgb_commit_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB_COMMIT), tiny_bset! {
Expand Down
24 changes: 20 additions & 4 deletions src/vm/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ impl<'op> OrdOpRef<'op> {
OrdOpRef::Genesis(_) => OpOrd::Genesis,
OrdOpRef::Transition(op, _, witness_ord) => OpOrd::Transition {
witness: *witness_ord,
ty: op.transition_type,
nonce: op.nonce,
opid: op.id(),
},
OrdOpRef::Extension(op, _, witness_ord) => OpOrd::Extension {
witness: *witness_ord,
ty: op.extension_type,
nonce: op.nonce,
opid: op.id(),
},
Expand Down Expand Up @@ -415,14 +417,14 @@ pub enum OpOrd {
#[strict_type(tag = 0x01)]
Extension {
witness: WitnessOrd,
// TODO: Consider using extension type here
ty: ExtensionType,
nonce: u64,
opid: OpId,
},
#[strict_type(tag = 0xFF)]
Transition {
witness: WitnessOrd,
// TODO: Consider using transition type here
ty: TransitionType,
nonce: u64,
opid: OpId,
},
Expand Down Expand Up @@ -465,20 +467,34 @@ impl GlobalOrd {
idx,
}
}
pub fn transition(opid: OpId, idx: u16, nonce: u64, witness: WitnessOrd) -> Self {
pub fn transition(
opid: OpId,
idx: u16,
ty: TransitionType,
nonce: u64,
witness: WitnessOrd,
) -> Self {
Self {
op_ord: OpOrd::Transition {
witness,
ty,
nonce,
opid,
},
idx,
}
}
pub fn extension(opid: OpId, idx: u16, nonce: u64, witness: WitnessOrd) -> Self {
pub fn extension(
opid: OpId,
idx: u16,
ty: ExtensionType,
nonce: u64,
witness: WitnessOrd,
) -> Self {
Self {
op_ord: OpOrd::Extension {
witness,
ty,
nonce,
opid,
},
Expand Down
30 changes: 17 additions & 13 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-----BEGIN STRICT TYPE LIB-----
Id: stl:LpE2Q!Jf-pKsvjM$-ntKgUld-!zeRRa!-v7l6pzJ-qW2YceY#africa-choice-biology
Id: stl:bioTBozT-NqelHGE-SPbnpMA-XBNSbXZ-6X0dANE-WHVirL8#explain-marvin-bless
Name: RGBLogic
Dependencies:
RGBCommit#tuna-safari-design,
BPCore#totem-holiday-helena,
Bitcoin#signal-color-cipher
Check-SHA256: ec5fbe3beec7e0816d76eb90ea8fb35c931847f2b189f7befdde4e7e16d53e18
Check-SHA256: b4f6b967a70e12d12c5831aa223bd85052f40dbc2bfd5ab3f739e1aa37242f31

2vSEvOmAmtV*_Nw)d@|xKsr716mTQmaB}ROZ@Dgs2ia_2=g^?i+KdTOM?ynyZEb0ErdhI3FM~0|p{<6(
sS&)~H{Xkb4j+}v9*QG}Q6KKm20~CnZ*pbzY!hN5_Bp3Y36tDMM#=e#tGI($UA5U3KNx<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aB}ROZ@Dgs2ia_2=g^?i+Ke<(53UoI8eY9A{1GERg--GiI0S#x1is&)
M%fmnGH3;EZ*F5{000OCZ*Xa30%XM12~D{`Iz96ga3kGta_pUNxh{zZ*=%3u(4f-VjFrgddLDIRU(}XW
LTZugenOC;Z(5k~zEJnJiX;;E#R^wxbZ%vHb5C+)1OosFVRB<=X?A5~000011#M|=Wn=&a0Raxbxa~M%
Zlr^{H1ibsRCVcA*+(@K+$R_oJY%-uiLn9+bY*UIVRUJBWdHyG3Rh`#Ze??GP;YYv0tRShX=iA3000CD
bZKp6b97;CZ~y>E

-----END STRICT TYPE LIB-----

Binary file modified stl/[email protected]
Binary file not shown.
8 changes: 6 additions & 2 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: stl:LpE2Q!Jf-pKsvjM$-ntKgUld-!zeRRa!-v7l6pzJ-qW2YceY#africa-choice-biology
Id: stl:bioTBozT-NqelHGE-SPbnpMA-XBNSbXZ-6X0dANE-WHVirL8#explain-marvin-bless
Name: RGBLogic
Version: 0.1.0
Description: Consensus logic layer for RGB smart contracts
Expand All @@ -12,6 +12,8 @@
typelib RGBLogic

import RGBCommit#tuna-safari-design
use TransitionType#picture-reflex-brigade
use ExtensionType#apropos-scoop-viva
use OpId#picnic-single-gloria

import BPCore#totem-holiday-helena
Expand All @@ -37,12 +39,14 @@ data DbcProof : tapret#1 BPCore.TapretProof
@mnemonic(east-sunset-extra)
data GlobalOrd : opOrd OpOrd, idx U16

@mnemonic(france-fish-fortune)
@mnemonic(combat-henry-flood)
data OpOrd : genesis ()
| extension (witness WitnessOrd
, ty RGBCommit.ExtensionType
, nonce U64
, opid RGBCommit.OpId)
| transition#255 (witness WitnessOrd
, ty RGBCommit.TransitionType
, nonce U64
, opid RGBCommit.OpId)

Expand Down

0 comments on commit d465448

Please sign in to comment.