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 17, 2024
1 parent 103b1da commit 8627f94
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:2$mqHGq5-aV!EhyM-GzDQ0TR-1$98P$3-!2lleId-xAOxKOU#nova-lobby-dialog";
/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB_LOGIC: &str =
"stl:w3K7P7FD-SQ36YW9-C4zqzxS-9RCkgd$-osrL6RV-gk11t!g#satire-vital-richard";
"stl:HgC$jfcl-ooeEyLQ-Fn4ixZg-Z6m5zh2-TQwRbCP-prFfNn4#soprano-nice-total";

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 @@ -418,14 +420,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 @@ -468,20 +470,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:w3K7P7FD-SQ36YW9-C4zqzxS-9RCkgd$-osrL6RV-gk11t!g#satire-vital-richard
Id: stl:HgC$jfcl-ooeEyLQ-Fn4ixZg-Z6m5zh2-TQwRbCP-prFfNn4#soprano-nice-total
Name: RGBLogic
Dependencies:
BPCore#garbo-radius-peru,
RGBCommit#nova-lobby-dialog,
Bitcoin#signal-color-cipher
Check-SHA256: b385c363a383d9a2cce01e0c7b4e75acd48725312341a0dcfe23317f431e744b
Check-SHA256: 0a097ab0847c6dd483bfc7462de13f75a93b22c120ba80fa68eee94143b8be36

2vSEvOmAmtV*_s<midRhTh1hu7-!n@1Cr{swqbZoGSd8tmgp<3rE>;CP(yEWW!w3x9BR2~UxbGv2Fx@x
O&x#t!~fsyrIq3x!~?M?<q1+pLPKwDZE1A%Y!hN5_Bp3Y36tDMM#=e#tGI($UA5U3KNx<*C>ja}LTPkk
Expand All @@ -17,17 +17,21 @@ Wpq+$XJ~Xna$#;`Xh%-ZT+rxDK6vW;JU&?LxLM72H?wDC1Zo}=N}D)4mkLjCa%FT-a&K>D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fsyrIq3x!~?M?<(0_hdLDIRU(}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:w3K7P7FD-SQ36YW9-C4zqzxS-9RCkgd$-osrL6RV-gk11t!g#satire-vital-richard
Id: stl:HgC$jfcl-ooeEyLQ-Fn4ixZg-Z6m5zh2-TQwRbCP-prFfNn4#soprano-nice-total
Name: RGBLogic
Version: 0.1.0
Description: Consensus logic layer for RGB smart contracts
Expand All @@ -19,6 +19,8 @@ import BPCore#garbo-radius-peru
use OpretProof#good-village-flex
import RGBCommit#nova-lobby-dialog
use TransitionType#picture-reflex-brigade
use ExtensionType#apropos-scoop-viva
use OpId#picnic-single-gloria
import Bitcoin#signal-color-cipher
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 8627f94

Please sign in to comment.