consensus: slot configuration updated, transactions per proposal cap added

This commit is contained in:
aggstam
2022-12-06 22:23:30 +02:00
parent 0a93bf24d6
commit 8f7ae3f6e9
3 changed files with 29 additions and 20 deletions

View File

@@ -25,7 +25,7 @@ contract "Lead" {
circuit "Lead" {
ZERO = witness_base(0);
ONE = witness_base(1);
REWARD = witness_base(420);
REWARD = witness_base(1);
PREFIX_EVL = witness_base(2);
PREFIX_SEED = witness_base(3);
PREFIX_CM = witness_base(4);

View File

@@ -71,13 +71,16 @@ pub const BLOCK_INFO_MAGIC_BYTES: [u8; 4] = [0x90, 0x44, 0xf1, 0xf6];
pub const EPOCH_LENGTH: usize = 10;
/// Slot time in seconds
pub const SLOT_TIME: u64 = 20;
pub const SLOT_TIME: u64 = 90;
/// Finalization sync period duration (should be >=1/4 of slot time)
pub const FINAL_SYNC_DUR: u64 = 5;
/// Finalization sync period duration (should be >=2/3 of slot time)
pub const FINAL_SYNC_DUR: u64 = 60;
/// Transactions included in a block cap
pub const TXS_CAP: usize = 50;
/// Block leader reward
pub const REWARD: u64 = 420;
pub const REWARD: u64 = 1;
/// Leader proofs k for zk proof rows (rows=2^k)
pub const LEADER_PROOF_K: u32 = 13;

View File

@@ -308,23 +308,29 @@ impl ValidatorState {
/// Retrieve all unconfirmed transactions not proposed in previous blocks
/// of provided index chain.
pub fn unproposed_txs(&self, index: i64) -> Vec<Transaction> {
let mut unproposed_txs = self.unconfirmed_txs.clone();
// If index is -1 (canonical blockchain) a new fork will be generated,
// therefore all unproposed transactions can be included in the proposal.
if index == -1 {
return unproposed_txs
}
// We iterate over the fork chain proposals to find already proposed
// transactions and remove them from the local unproposed_txs vector.
let chain = &self.consensus.forks[index as usize];
for state_checkpoint in &chain.sequence {
for tx in &state_checkpoint.proposal.block.txs {
if let Some(pos) = unproposed_txs.iter().position(|txs| *txs == *tx) {
unproposed_txs.remove(pos);
let unproposed_txs = if index == -1 {
// If index is -1 (canonical blockchain) a new fork will be generated,
// therefore all unproposed transactions can be included in the proposal.
self.unconfirmed_txs.clone()
} else {
// We iterate over the fork chain proposals to find already proposed
// transactions and remove them from the local unproposed_txs vector.
let mut filtered_txs = self.unconfirmed_txs.clone();
let chain = &self.consensus.forks[index as usize];
for state_checkpoint in &chain.sequence {
for tx in &state_checkpoint.proposal.block.txs {
if let Some(pos) = filtered_txs.iter().position(|txs| *txs == *tx) {
filtered_txs.remove(pos);
}
}
}
filtered_txs
};
// Check if transactions exceed configured cap
let cap = constants::TXS_CAP;
if unproposed_txs.len() > cap {
return unproposed_txs[0..cap].to_vec()
}
unproposed_txs