NRD rules and "recent" kernel pos index (#3302)

* variants for output_pos linked list entries (head/tail/middle/unique)
next and prev and Vec<u8> lmdb keys

* get_pos on enum

* break list and list entries out into separate enums

* track output features in the new output_pos index, so we can determine coinbase maturity

* push entry impl for none and unique

* some test coverage for output_pos_list

* commit

* wip - FooListEntry

* use instance of the index

* linked list of output_pos and commit_pos both now supported

* linked_list

* cleanup and rename

* rename

* peek_pos

* push some, peek some, pop some

* cleanup

* commit pos
cleanup

* split list and entry out into separate db prefixes

* cleanup and add placeholder for pop_back

* pop_pos_back (for popping off the back of the linked list)
test coverage for pop_pos_back

* wip

* placeholder for prune via a trait
pos must always increase in the index

* rewind kernel_pos_idx when calling rewind_single_block

* RewindableListIndex with rewind support.

* test coverage for rewindable list index

* test coverage for rewind back to 0

* rewind past end of list

* add tests for kernel_pos_idx with multiple commits

* commit

* cleanup

* hook NRD relative lock height validation into block processing and tx validation

* cleanup

* set local chain type for kernel_idx tests

* add test coverage for NRD rules in block processing

* NRD test coverage and cleanup

* NRD relative height 1 test

* test coverage for NRD kernels in block processing

* cleanup

* start of test coverage for txpool NRD kernel rules

* wip

* rework pool tests to use real chain (was mock chain) to better reflect reality (tx/block validation rules etc.)

* cleanup

* cleanup pruneable trait for kernel pos index

* add clear() to kernel_pos idx and test coverage

* hook kernel_pos rebuild into node startup, compaction and fast sync

* verify full NRD history on fast sync

* return early if nrd disabled

* fix header sync issue
This commit is contained in:
Antioch Peverell
2020-06-10 16:38:29 +01:00
committed by GitHub
parent b98e5e06a6
commit 20e5c1910b
22 changed files with 2209 additions and 66 deletions
+32 -1
View File
@@ -909,6 +909,36 @@ impl TransactionBody {
Ok(())
}
// It is never valid to have multiple duplicate NRD kernels (by public excess)
// in the same transaction or block. We check this here.
// We skip this check if NRD feature is not enabled.
fn verify_no_nrd_duplicates(&self) -> Result<(), Error> {
if !global::is_nrd_enabled() {
return Ok(());
}
let mut nrd_excess: Vec<Commitment> = self
.kernels
.iter()
.filter(|x| match x.features {
KernelFeatures::NoRecentDuplicate { .. } => true,
_ => false,
})
.map(|x| x.excess())
.collect();
// Sort and dedup and compare length to look for duplicates.
nrd_excess.sort();
let original_count = nrd_excess.len();
nrd_excess.dedup();
let dedup_count = nrd_excess.len();
if original_count == dedup_count {
Ok(())
} else {
Err(Error::InvalidNRDRelativeHeight)
}
}
// Verify that inputs|outputs|kernels are sorted in lexicographical order
// and that there are no duplicates (they are all unique within this transaction).
fn verify_sorted(&self) -> Result<(), Error> {
@@ -970,6 +1000,7 @@ impl TransactionBody {
/// * kernel signature verification
pub fn validate_read(&self, weighting: Weighting) -> Result<(), Error> {
self.verify_weight(weighting)?;
self.verify_no_nrd_duplicates()?;
self.verify_sorted()?;
self.verify_cut_through()?;
Ok(())
@@ -1227,8 +1258,8 @@ impl Transaction {
weighting: Weighting,
verifier: Arc<RwLock<dyn VerifierCache>>,
) -> Result<(), Error> {
self.body.validate(weighting, verifier)?;
self.body.verify_features()?;
self.body.validate(weighting, verifier)?;
self.verify_kernel_sums(self.overage(), self.offset.clone())?;
Ok(())
}