Add validateServiceTransactionsTransition spec option

This commit is contained in:
POA 2021-11-12 13:06:19 +03:00
parent caa210107e
commit b981f7beef
4 changed files with 51 additions and 41 deletions

View File

@ -45,7 +45,7 @@ impl ServiceTransactionChecker {
) -> Result<bool, String> { ) -> Result<bool, String> {
let sender = tx.sender(); let sender = tx.sender();
// Skip checking the contract if the transaction does not have zero gas price // Skip checking the contract if the transaction does not have zero gas price
if !tx.tx().gas_price.is_zero() { if !tx.has_zero_gas_price() {
return Ok(false); return Ok(false);
} }

View File

@ -488,48 +488,50 @@ impl Importer {
.epoch_transition(parent.number(), *header.parent_hash()) .epoch_transition(parent.number(), *header.parent_hash())
.is_some(); .is_some();
// Check if zero gas price transactions are certified to be service transactions if header.number() >= engine.params().validate_service_transactions_transition {
// using the Certifier contract. If they are not certified, the block is treated as invalid. // Check if zero gas price transactions are certified to be service transactions
let service_transaction_checker = self.miner.service_transaction_checker(); // using the Certifier contract. If they are not certified, the block is treated as invalid.
if service_transaction_checker.is_some() { let service_transaction_checker = self.miner.service_transaction_checker();
match service_transaction_checker.unwrap().refresh_cache(client) { if service_transaction_checker.is_some() {
Ok(true) => { match service_transaction_checker.unwrap().refresh_cache(client) {
trace!(target: "client", "Service transaction cache was refreshed successfully"); Ok(true) => {
} trace!(target: "client", "Service transaction cache was refreshed successfully");
Ok(false) => {
trace!(target: "client", "Registrar or/and service transactions contract does not exist");
}
Err(e) => {
error!(target: "client", "Error occurred while refreshing service transaction cache: {}", e)
}
};
};
for t in &block.transactions {
if t.has_zero_gas_price() {
match self.miner.service_transaction_checker() {
None => {
let e = "Service transactions are not allowed. You need to enable Certifier contract.";
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
} }
Some(ref checker) => match checker.check(client, &t) { Ok(false) => {
Ok(true) => {} trace!(target: "client", "Registrar or/and service transactions contract does not exist");
Ok(false) => { }
let e = format!( Err(e) => {
"Service transactions are not allowed for the sender {:?}", error!(target: "client", "Error occurred while refreshing service transaction cache: {}", e)
t.sender() }
); };
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
}
Err(e) => {
debug!(target: "client", "Unable to verify service transaction: {:?}", e);
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
}
},
}
}; };
for t in &block.transactions {
if t.has_zero_gas_price() {
match self.miner.service_transaction_checker() {
None => {
let e = "Service transactions are not allowed. You need to enable Certifier contract.";
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
}
Some(ref checker) => match checker.check(client, &t) {
Ok(true) => {}
Ok(false) => {
let e = format!(
"Service transactions are not allowed for the sender {:?}",
t.sender()
);
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
}
Err(e) => {
debug!(target: "client", "Unable to verify service transaction: {:?}", e);
warn!(target: "client", "Service tx checker error: {:?}", e);
bail!(e);
}
},
}
};
}
} }
// t_nb 8.0 Block enacting. Execution of transactions. // t_nb 8.0 Block enacting. Execution of transactions.

View File

@ -191,6 +191,8 @@ pub struct CommonParams {
pub eip1559_fee_collector: Option<Address>, pub eip1559_fee_collector: Option<Address>,
/// Block at which the fee collector should start being used. /// Block at which the fee collector should start being used.
pub eip1559_fee_collector_transition: BlockNumber, pub eip1559_fee_collector_transition: BlockNumber,
/// Block at which zero gas price transactions start being checked with Certifier contract.
pub validate_service_transactions_transition: BlockNumber,
} }
impl CommonParams { impl CommonParams {
@ -475,6 +477,9 @@ impl From<ethjson::spec::Params> for CommonParams {
eip1559_fee_collector_transition: p eip1559_fee_collector_transition: p
.eip1559_fee_collector_transition .eip1559_fee_collector_transition
.map_or_else(BlockNumber::max_value, Into::into), .map_or_else(BlockNumber::max_value, Into::into),
validate_service_transactions_transition: p
.validate_service_transactions_transition
.map_or_else(BlockNumber::max_value, Into::into),
} }
} }
} }
@ -752,6 +757,7 @@ impl Spec {
params.transaction_permission_contract_transition, params.transaction_permission_contract_transition,
params.eip1559_fee_collector_transition, params.eip1559_fee_collector_transition,
params.eip1559_base_fee_min_value_transition, params.eip1559_base_fee_min_value_transition,
params.validate_service_transactions_transition,
]; ];
// BUG: Rinkeby has homestead transition at block 1 but we can't reflect that in specs for non-Ethash networks // BUG: Rinkeby has homestead transition at block 1 but we can't reflect that in specs for non-Ethash networks
if params.network_id == 0x4 { if params.network_id == 0x4 {

View File

@ -166,6 +166,8 @@ pub struct Params {
pub eip1559_fee_collector: Option<Address>, pub eip1559_fee_collector: Option<Address>,
/// Block at which the fee collector should start being used. /// Block at which the fee collector should start being used.
pub eip1559_fee_collector_transition: Option<Uint>, pub eip1559_fee_collector_transition: Option<Uint>,
/// Block at which zero gas price transactions start being checked with Certifier contract.
pub validate_service_transactions_transition: Option<Uint>,
} }
#[cfg(test)] #[cfg(test)]