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

Fix sat index test #2154

Merged
merged 2 commits into from
Jun 6, 2023
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
65 changes: 37 additions & 28 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,35 +837,44 @@ impl Index {
inscription_id,
);

if let Some(sat) = sat {
if self.has_sat_index().unwrap() {
assert_eq!(
InscriptionId::load(
*rtx
.open_table(SAT_TO_INSCRIPTION_ID)
.unwrap()
.get(&sat)
.unwrap()
.unwrap()
.value()
),
inscription_id,
);

// we do not track common sats or anything in the unbound output
if !Sat(sat).is_common() && satpoint.outpoint != unbound_outpoint() {
match sat {
Some(sat) => {
if self.has_sat_index().unwrap() {
// unbound inscriptions should not be assigned to a sat
assert!(satpoint.outpoint != unbound_outpoint());
assert_eq!(
SatPoint::load(
InscriptionId::load(
*rtx
.open_table(SAT_TO_SATPOINT)
.open_table(SAT_TO_INSCRIPTION_ID)
.unwrap()
.get(&sat)
.unwrap()
.unwrap()
.value()
),
satpoint,
inscription_id,
);

// we do not track common sats (only the sat ranges)
if !Sat(sat).is_common() {
assert_eq!(
SatPoint::load(
*rtx
.open_table(SAT_TO_SATPOINT)
.unwrap()
.get(&sat)
.unwrap()
.unwrap()
.value()
),
satpoint,
);
}
}
}
None => {
if self.has_sat_index().unwrap() {
assert!(satpoint.outpoint == unbound_outpoint())
}
}
}
Expand Down Expand Up @@ -2177,7 +2186,7 @@ mod tests {
outpoint: unbound_outpoint(),
offset: 0,
},
Some(50 * COIN_VALUE),
None, // should not be on a sat
);

assert!(context
Expand Down Expand Up @@ -2354,7 +2363,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 0,
},
None,
Some(50 * COIN_VALUE),
);

context.index.assert_inscription_location(
Expand All @@ -2363,7 +2372,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 50 * COIN_VALUE,
},
None,
Some(100 * COIN_VALUE),
);

context.index.assert_inscription_location(
Expand All @@ -2372,7 +2381,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 100 * COIN_VALUE,
},
None,
Some(150 * COIN_VALUE),
);

assert_eq!(
Expand Down Expand Up @@ -2459,7 +2468,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 0,
},
None,
Some(50 * COIN_VALUE),
);

context.index.assert_inscription_location(
Expand Down Expand Up @@ -2566,7 +2575,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 0,
},
None,
Some(50 * COIN_VALUE),
);

context.index.assert_inscription_location(
Expand All @@ -2575,7 +2584,7 @@ mod tests {
outpoint: OutPoint { txid, vout: 0 },
offset: 50 * COIN_VALUE,
},
None,
Some(100 * COIN_VALUE),
);

context.index.assert_inscription_location(
Expand Down Expand Up @@ -2718,7 +2727,7 @@ mod tests {
},
offset: 0,
},
None,
Some(100 * COIN_VALUE),
);

assert_eq!(
Expand Down
29 changes: 17 additions & 12 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,25 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {

self.number_to_id.insert(number, &inscription_id)?;

let mut sat = None;
if let Some(input_sat_ranges) = input_sat_ranges {
let mut offset = 0;
for (start, end) in input_sat_ranges {
let size = end - start;
if offset + size > flotsam.offset {
let n = start + flotsam.offset - offset;
self.sat_to_inscription_id.insert(&n, &inscription_id)?;
sat = Some(Sat(n));
break;
let sat = if unbound {
None
} else {
let mut sat = None;
if let Some(input_sat_ranges) = input_sat_ranges {
let mut offset = 0;
for (start, end) in input_sat_ranges {
let size = end - start;
if offset + size > flotsam.offset {
let n = start + flotsam.offset - offset;
self.sat_to_inscription_id.insert(&n, &inscription_id)?;
sat = Some(Sat(n));
break;
}
offset += size;
}
offset += size;
}
}
sat
};

self.id_to_entry.insert(
&inscription_id,
Expand Down