Skip to content

Commit

Permalink
fix(contract-index): adds support for ContractAmendment to contract i…
Browse files Browse the repository at this point in the history
…ndex (#4214)

Description
---
Adds support for ContractAmendment output type to contract index

Motivation and Context
---
ContractAmendments are currently rejected. This PR allows them to be added to the contract index. 

How Has This Been Tested?
---
Manually
  • Loading branch information
sdbondi committed Jun 28, 2022
1 parent 3d8a3b2 commit a41d0c9
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions base_layer/core/src/chain_storage/lmdb_db/contract_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ where T: Deref<Target = ConstTransaction<'a>>
) -> Result<Vec<FixedHash>, ChainStorageError> {
let key = ContractIndexKey::new(contract_id, output_type);
match output_type {
OutputType::ContractDefinition | OutputType::ContractCheckpoint | OutputType::ContractConstitution => {
Ok(self
.get::<_, ContractIndexValue>(&key)?
.into_iter()
.map(|v| v.output_hash)
.collect())
},
OutputType::ContractAmendment |
OutputType::ContractDefinition |
OutputType::ContractCheckpoint |
OutputType::ContractConstitution => Ok(self
.get::<_, ContractIndexValue>(&key)?
.into_iter()
.map(|v| v.output_hash)
.collect()),

OutputType::ContractValidatorAcceptance |
OutputType::ContractConstitutionProposal |
OutputType::ContractConstitutionChangeAcceptance => Ok(self
Expand All @@ -106,9 +108,11 @@ where T: Deref<Target = ConstTransaction<'a>>
) -> Result<Vec<FixedHash>, ChainStorageError> {
let key = BlockContractIndexKey::prefixed(block_hash, output_type);
match output_type {
OutputType::ContractDefinition | OutputType::ContractCheckpoint | OutputType::ContractConstitution => {
self.get_all_matching::<_, FixedHash>(&key)
},
OutputType::ContractDefinition |
OutputType::ContractCheckpoint |
OutputType::ContractConstitution |
OutputType::ContractAmendment => self.get_all_matching::<_, FixedHash>(&key),

OutputType::ContractValidatorAcceptance |
OutputType::ContractConstitutionProposal |
OutputType::ContractConstitutionChangeAcceptance => Ok(self
Expand Down Expand Up @@ -227,7 +231,7 @@ impl<'a> ContractIndex<'a, WriteTransaction<'a>> {
},
// Only one contract checkpoint and constitution can exist at a time and can be overwritten. Consensus rules
// decide whether this is valid but we just assume this is valid here.
OutputType::ContractConstitution | OutputType::ContractCheckpoint => {
OutputType::ContractAmendment | OutputType::ContractConstitution | OutputType::ContractCheckpoint => {
self.assert_definition_exists(contract_id)?;
self.set(&contract_key, &ContractIndexValue {
block_hash,
Expand All @@ -239,8 +243,7 @@ impl<'a> ContractIndex<'a, WriteTransaction<'a>> {
// These are collections of output hashes
OutputType::ContractValidatorAcceptance |
OutputType::ContractConstitutionProposal |
OutputType::ContractConstitutionChangeAcceptance |
OutputType::ContractAmendment => {
OutputType::ContractConstitutionChangeAcceptance => {
self.assert_definition_exists(contract_id)?;
self.add_to_set(&contract_key, ContractIndexValue {
block_hash,
Expand Down Expand Up @@ -280,7 +283,7 @@ impl<'a> ContractIndex<'a, WriteTransaction<'a>> {
self.delete(&block_key)?;
Ok(())
},
OutputType::ContractConstitution | OutputType::ContractCheckpoint => {
OutputType::ContractAmendment | OutputType::ContractConstitution | OutputType::ContractCheckpoint => {
let contract = self.get_and_delete::<_, ContractIndexValue>(&contract_key)?;
let block_key = BlockContractIndexKey::new(contract.block_hash, output_type, contract_id);
self.delete(&block_key)?;
Expand Down

0 comments on commit a41d0c9

Please sign in to comment.