Skip to content

Commit

Permalink
persistence: support multiple terminals per operation output
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Sep 17, 2024
1 parent d28d7e6 commit 4c84a0a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 51 deletions.
52 changes: 43 additions & 9 deletions src/persistence/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ pub struct MemIndex {
bundle_contract_index: MediumOrdMap<BundleId, ContractId>,
bundle_witness_index: MediumOrdMap<BundleId, TinyOrdSet<XWitnessId>>,
contract_index: TinyOrdMap<ContractId, ContractIndex>,
terminal_index: MediumOrdMap<XChain<SecretSeal>, Opout>,
terminal_index: MediumOrdMap<XChain<SecretSeal>, TinyOrdSet<Opout>>,
}

impl StrictSerialize for MemIndex {}
Expand Down Expand Up @@ -1324,7 +1324,8 @@ impl IndexReadProvider for MemIndex {
.terminal_index
.iter()
.filter(|(seal, _)| terminals.contains(*seal))
.map(|(_, opout)| *opout)
.flat_map(|(_, opout)| opout.iter())
.copied()

Check warning on line 1328 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1327-L1328

Added lines #L1327 - L1328 were not covered by tests
.collect())
}

Expand Down Expand Up @@ -1427,9 +1428,9 @@ impl IndexWriteProvider for MemIndex {
.get_mut(&contract_id)
.ok_or(IndexInconsistency::ContractAbsent(contract_id))?;

for (no, a) in vec.iter().enumerate() {
for (no, assign) in vec.iter().enumerate() {

Check warning on line 1431 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1431

Added line #L1431 was not covered by tests
let opout = Opout::new(opid, type_id, no as u16);
if let Assign::ConfidentialState { seal, .. } | Assign::Revealed { seal, .. } = a {
if let Assign::ConfidentialState { seal, .. } | Assign::Revealed { seal, .. } = assign {

Check warning on line 1433 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1433

Added line #L1433 was not covered by tests
let output = seal
.to_output_seal()
.expect("genesis seals always have outpoint");
Expand All @@ -1442,11 +1443,10 @@ impl IndexWriteProvider for MemIndex {
}
}
}
if let Assign::Confidential { seal, .. } | Assign::ConfidentialSeal { seal, .. } = a {
self.terminal_index.insert(*seal, opout)?;
}
}
Ok(())

// We need two cycles due to the borrow checker
self.extend_terminals(vec, opid, type_id)

Check warning on line 1449 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1449

Added line #L1449 was not covered by tests
}

fn index_transition_assignments<State: ExposedState>(
Expand Down Expand Up @@ -1481,10 +1481,44 @@ impl IndexWriteProvider for MemIndex {
}
}
}
}

// We need two cycles due to the borrow checker
self.extend_terminals(vec, opid, type_id)
}

Check warning on line 1488 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1487-L1488

Added lines #L1487 - L1488 were not covered by tests
}

impl MemIndex {
fn extend_terminals<State: ExposedState, Seal: ExposedSeal>(
&mut self,
vec: &[Assign<State, Seal>],
opid: OpId,
type_id: AssignmentType,
) -> Result<(), IndexWriteError<MemError>> {
for (no, assign) in vec.iter().enumerate() {
let opout = Opout::new(opid, type_id, no as u16);

Check warning on line 1499 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1492-L1499

Added lines #L1492 - L1499 were not covered by tests
if let Assign::Confidential { seal, .. } | Assign::ConfidentialSeal { seal, .. } =
assign
{
self.terminal_index.insert(*seal, opout)?;
self.add_terminal(*seal, opout)?;
}

Check warning on line 1504 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1503-L1504

Added lines #L1503 - L1504 were not covered by tests
}
Ok(())
}

Check warning on line 1507 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1506-L1507

Added lines #L1506 - L1507 were not covered by tests

fn add_terminal(
&mut self,
seal: XChain<SecretSeal>,
opout: Opout,
) -> Result<(), IndexWriteError<MemError>> {
match self
.terminal_index
.remove(&seal)
.expect("can have zero elements")

Check warning on line 1517 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1509-L1517

Added lines #L1509 - L1517 were not covered by tests
{
Some(mut existing_opouts) => existing_opouts.push(opout)?,

Check warning on line 1519 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1519

Added line #L1519 was not covered by tests
None => {
self.terminal_index.insert(seal, tiny_bset![opout])?;

Check warning on line 1521 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1521

Added line #L1521 was not covered by tests
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/stl/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::LIB_NAME_RGB_STD;
/// Strict types id for the library providing standard data types which may be
/// used in RGB smart contracts.
pub const LIB_ID_RGB_STORAGE: &str =
"stl:ieoE!c74-z5Us1Cc-j6$RdoB-BWAdWBF-jwE9Vu7-sFCnYdI#lopez-alert-slow";
"stl:ZVab0Axk-3hHvPBw-PVgbKK9-OjbajRO-sbN53sE-De3$HdM#cabinet-emerald-brush";

/// Strict types id for the library providing standard data types which may be
/// used in RGB smart contracts.
Expand Down
77 changes: 39 additions & 38 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-----BEGIN STRICT TYPE LIB-----
Id: stl:ieoE!c74-z5Us1Cc-j6$RdoB-BWAdWBF-jwE9Vu7-sFCnYdI#lopez-alert-slow
Id: stl:ZVab0Axk-3hHvPBw-PVgbKK9-OjbajRO-sbN53sE-De3$HdM#cabinet-emerald-brush
Name: RGBStorage
Dependencies:
RGBStd#picnic-reverse-convert,
Expand All @@ -11,7 +11,7 @@ Dependencies:
BPCore#totem-holiday-helena,
Std#ralph-blue-lucky,
Bitcoin#signal-color-cipher
Check-SHA256: e92b99ae1abe013f0fae063ec109b931cfd4d7bc645988b39dd559495485266b
Check-SHA256: eb80a555081e5cd6c487489afaa6035c7871cc544a4e7098144d9f2b9455724e

3Q|WxQ*>`~VP|CtF%(Tiw}_hL!Gmq7aiBy4V-l87!ykk~3_hpwOT62w22w{tQ*>lS>Z4!V_T!KNI`QJ|
h6;Zj^jB$MPK+?7Lu3>C`4HI)Q*?4^V{}w`aAk91a5aA+<>R2XhQO_4{AcS-HH^7AVzASV8M4NYxyCjH
Expand Down Expand Up @@ -181,42 +181,43 @@ J@XWBBi(Rv?4579E{O-(Y+vWlpwilmiECIT&Bl;lSX#$ms8AQN7m&qY<e5Qw(E}jxBS#zY0000000000
{{R30000000000000000|Ns90000004P$R^baG*1bV+VxWq1Gz0%XM12~D{`Iz96ga3kGta_pUNxh{zZ
*=%3u(4f-VjGqWBNjk^^qPoT1+zTRnAg`3vXv9d*8d@RXy~6c6G65{qa?ZI2j;&_LbXP8tT1(-d>UXjT
-wZT0^&Yy7N)`YB000000093000000000eiWpZt4ZeeUmZe(S6015(R#MKE+xj;HS^AvC+-Eea3oo~4=
i3iziU+2)E(%OvMidq_i6cBYN^7xEELu$lFU37Sf$J;ty5yrmOX|)6bWW?18O}RiiJ@XWBBi(Rv?4579
E{O-(Y+vWlpwilmlMuXsu{2tXFT+?;?hj39&>gq>HOrf1lB-q;n)I5N0000000000|Ns90000002u)>e
Q*>c-Xa)@kb7N>_ZDDj_015(R#MKE+xj;HS^AvC+-Eea3oo~4=i3iziU+2)E(%OuaQq$W5tE;F{pQrXd
&=l*`O?@#x{Qdy?T_k!`1dtE{F%(Tiw}_hL!Gmq7aiBy4V-l87!ykk~3_hpwOT62w(swU)=eHZcWUx8U
##PM;a30K-=Jl8VtAf?Zi=Hx60000000000{{R300000025DwtV`Xyy3IZ_{O+>edn&iQQZK-jfL<3_I
mQceVghC8Hr}9g@+p9auz<~n@;VY|KA!vt$<F<39SJ>qMEp^75#kD_Tqj3T;6ir08h??ZVgKepCphN>>
5|&WIAA~{-KBw|ayxXfe#~MC<5IE1bzMOP@>#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ziU+2)E(%Ou+
=zxYCD0L!x4tB5Hm3vFbl?lapNXe%XU~*fKJ0+X~F%(Tiw}_hL!Gmq7aiBy4V-l87!ykk~3_hpwOT62w
qTpH7(Xh=OrK%E4t`xv**_;YjPG|`q@y<~A1W*K^0000000000|Nj60000001Z-(ya{vkgVsJHoA?4$s
wuZp1Wc+9AOf`(TIbyKWjTy4WkGaM+r!Z9lE%{u?@QI^EqCb}2Q7OO^w+`_q*ddTXmHSf)0%CAAe<9`L
ptgp<tz`UX>r6F_xjAC6(~TLj#*ewiHWCD<wgM1*ibOB<Hr54hSy}kyId~TM4gJLrad1S=<^TWy00000
0RR600000000eVsXLA4w0x=X#M7M~V<iUe&sd1o017i}FP{SXDLJU5q@=LtitK!rZP!Z9Fy4s@&s7y*h
O1UlNfirx{z*_V4e8lMKAp$WJO+>edn&iQQZK-jfL<3_ImQceVghC8Hr}9g@+pC5c5G-hCV9w&(UffE`
hM!G~aLQ!~gAR@AcC9KZUqt`_000000096000000000P0Wo=V*VRU5%0tt6%bZ%vHb7gY?3Ib%r)d@|x
Ksr716mTQmaB}ROZ@Dgs2ia_2=g^?i+Kh>7SS8KIkY89@$6%;X7qJ(R#b4x^L3+^xAn+qc8}R~eDia2b
(>AB29AOeYx#=(k!8In=XQlLX14LMLVywUR3nQ8ri$WPp5w@a4b3LR7M69fMnD+{F6rHCsWOZ=>00000
00030|Ns9000009V{dMBa$#e1a{vkgWW?18O}RiiJ@XWBBi(Rv?4579E{O-(Y+vWlpwilmp9m~TI>-W|
y2ahx3nF|Vuawki#7NH?S|Q-Q!u2{b0d|^F*?W9|>m72;^XjNjCf456piKdvUO#1@>k1Zy`v3p{00000
0RI300000000

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

Binary file modified stl/[email protected]
Binary file not shown.
6 changes: 3 additions & 3 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: stl:ieoE!c74-z5Us1Cc-j6$RdoB-BWAdWBF-jwE9Vu7-sFCnYdI#lopez-alert-slow
Id: stl:ZVab0Axk-3hHvPBw-PVgbKK9-OjbajRO-sbN53sE-De3$HdM#cabinet-emerald-brush
Name: RGBStorage
Version: 0.11.0
Description: RGB storage library
Expand Down Expand Up @@ -231,12 +231,12 @@ data MemContractState : schemaId RGBCommit.SchemaId
@mnemonic(gilbert-torpedo-digital)
data MemGlobalState : known {RGBStd.GlobalOut -> ^ ..0xffffffff RGBCommit.DataState}, limit U24
@mnemonic(origin-flame-actor)
@mnemonic(savage-joshua-clone)
data MemIndex : opBundleIndex {RGBCommit.OpId -> ^ ..0xffffff RGBCommit.BundleId}
, bundleContractIndex {RGBCommit.BundleId -> ^ ..0xffffff RGBCommit.ContractId}
, bundleWitnessIndex {RGBCommit.BundleId -> ^ ..0xffffff {RGBCommit.XChainTxid ^ ..0xff}}
, contractIndex {RGBCommit.ContractId -> ^ ..0xff ContractIndex}
, terminalIndex {RGBCommit.XChainSecretSeal -> ^ ..0xffffff RGBCommit.Opout}
, terminalIndex {RGBCommit.XChainSecretSeal -> ^ ..0xffffff {RGBCommit.Opout ^ ..0xff}}
@mnemonic(ultra-sweden-limbo)
data MemStash : schemata {RGBCommit.SchemaId -> ^ ..0xff RGBStd.SchemaIfaces}
Expand Down

0 comments on commit 4c84a0a

Please sign in to comment.