Skip to content
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
16 changes: 10 additions & 6 deletions chain-impl-mockchain/benches/tally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ fn tally_benchmark(
);

res.push(controller.fragment_factory().vote_cast(
BlockDate::first(),
private_voter,
VoteCast::new(vote_plan.to_id(), proposal_idx as u8, payload),
));
Expand Down Expand Up @@ -171,9 +172,11 @@ fn tally_benchmark(
let mut alice = controller.wallet(ALICE).unwrap();

let encrypted_tally = EncryptedVoteTally::new(vote_plan.to_id());
let fragment = controller
.fragment_factory()
.vote_encrypted_tally(&alice, encrypted_tally);
let fragment = controller.fragment_factory().vote_encrypted_tally(
BlockDate::first(),
&alice,
encrypted_tally,
);

let parameters = ledger.parameters.clone();
let date = ledger.date();
Expand Down Expand Up @@ -264,9 +267,10 @@ fn tally_benchmark(

let decrypted_tally =
VoteTally::new_private(vote_plan.to_id(), DecryptedPrivateTally::new(shares));
let fragment = controller
.fragment_factory()
.vote_tally(&alice, decrypted_tally);
let fragment =
controller
.fragment_factory()
.vote_tally(BlockDate::first(), &alice, decrypted_tally);

c.bench_function(&format!("vote_tally_{}", benchmark_name), |b| {
b.iter(|| {
Expand Down
3 changes: 2 additions & 1 deletion chain-impl-mockchain/doc/format.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ UPDATE-VOTE = TODO
; note: IOW stand for Inputs-Outputs-Witnesses
; ####################

IOW = SIZE-ELEMENT-8BIT ; number of inputs
IOW = BLOCK-DATE ; end validity of this IOW
SIZE-ELEMENT-8BIT ; number of inputs
SIZE-ELEMENT-8BIT ; number of outputs
*INPUT ; as many as indicated in the number of inputs
*OUTPUT ; sa many as indicated in the number of outputs
Expand Down
2 changes: 2 additions & 0 deletions chain-impl-mockchain/src/certificate/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ mod tests {
use super::{PoolOwnersSigned, PoolPermissions};
use crate::{
chaintypes::HeaderId,
date::BlockDate,
key::EitherEd25519SecretKey,
testing::{
builders::{make_witness, StakePoolBuilder},
Expand Down Expand Up @@ -739,6 +740,7 @@ mod tests {

let builder = TxBuilder::new()
.set_payload(&NoExtra)
.set_expiry_date(BlockDate::first().next_epoch())
.set_ios(&pool_owner_with_sign.inputs(), &[]);
let auth_data_hash = builder.get_auth_data_for_witness().hash();
let builder = builder
Expand Down
12 changes: 11 additions & 1 deletion chain-impl-mockchain/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub enum ConfigParam {
AddCommitteeId(CommitteeId),
RemoveCommitteeId(CommitteeId),
PerVoteCertificateFees(PerVoteCertificateFee),
TransactionMaxExpiryEpochs(u8),
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -153,6 +154,8 @@ pub enum Tag {
RemoveCommitteeId = 27,
#[strum(to_string = "per-vote-certificate-fees")]
PerVoteCertificateFees = 28,
#[strum(to_string = "transaction-maximum-expiry-epochs")]
TransactionMaxExpiryEpochs = 29,
}

impl Tag {
Expand Down Expand Up @@ -183,6 +186,7 @@ impl Tag {
26 => Some(Tag::AddCommitteeId),
27 => Some(Tag::RemoveCommitteeId),
28 => Some(Tag::PerVoteCertificateFees),
29 => Some(Tag::TransactionMaxExpiryEpochs),
_ => None,
}
}
Expand Down Expand Up @@ -218,6 +222,7 @@ impl<'a> From<&'a ConfigParam> for Tag {
ConfigParam::AddCommitteeId(..) => Tag::AddCommitteeId,
ConfigParam::RemoveCommitteeId(..) => Tag::RemoveCommitteeId,
ConfigParam::PerVoteCertificateFees(..) => Tag::PerVoteCertificateFees,
ConfigParam::TransactionMaxExpiryEpochs(..) => Tag::TransactionMaxExpiryEpochs,
}
}
}
Expand Down Expand Up @@ -298,6 +303,9 @@ impl Readable for ConfigParam {
Tag::PerVoteCertificateFees => {
ConfigParamVariant::from_payload(bytes).map(ConfigParam::PerVoteCertificateFees)
}
Tag::TransactionMaxExpiryEpochs => {
ConfigParamVariant::from_payload(bytes).map(ConfigParam::TransactionMaxExpiryEpochs)
}
}
.map_err(Into::into)
}
Expand Down Expand Up @@ -334,6 +342,7 @@ impl property::Serialize for ConfigParam {
ConfigParam::AddCommitteeId(data) => data.to_payload(),
ConfigParam::RemoveCommitteeId(data) => data.to_payload(),
ConfigParam::PerVoteCertificateFees(data) => data.to_payload(),
ConfigParam::TransactionMaxExpiryEpochs(data) => data.to_payload(),
};
let taglen = TagLen::new(tag, bytes.len()).ok_or_else(|| {
io::Error::new(
Expand Down Expand Up @@ -858,7 +867,7 @@ mod test {

impl Arbitrary for ConfigParam {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
match u8::arbitrary(g) % 29 {
match u8::arbitrary(g) % 30 {
0 => ConfigParam::Block0Date(Arbitrary::arbitrary(g)),
1 => ConfigParam::Discrimination(Arbitrary::arbitrary(g)),
2 => ConfigParam::ConsensusVersion(Arbitrary::arbitrary(g)),
Expand Down Expand Up @@ -888,6 +897,7 @@ mod test {
26 => ConfigParam::AddCommitteeId(Arbitrary::arbitrary(g)),
27 => ConfigParam::RemoveCommitteeId(Arbitrary::arbitrary(g)),
28 => ConfigParam::PerCertificateFees(Arbitrary::arbitrary(g)),
29 => ConfigParam::TransactionMaxExpiryEpochs(Arbitrary::arbitrary(g)),
_ => unreachable!(),
}
}
Expand Down
27 changes: 27 additions & 0 deletions chain-impl-mockchain/src/ledger/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::{Block0Error, Error};
use crate::certificate;
use crate::date::BlockDate;
use crate::setting;
use crate::transaction::*;
use crate::value::Value;
use chain_addr::Address;
Expand Down Expand Up @@ -142,6 +144,10 @@ pub(super) fn valid_pool_update_certificate(reg: &certificate::PoolUpdate) -> Le
pub enum TxVerifyError {
#[error("too many outputs, expected maximum of {expected}, but received {actual}")]
TooManyOutputs { expected: u8, actual: u8 },
#[error("Transaction validity expired")]
TransactionExpired,
#[error("Transaction validity is too far in the future")]
TransactionValidForTooLong,
}

#[allow(clippy::absurd_extreme_comparisons)]
Expand All @@ -164,6 +170,27 @@ pub(super) fn valid_transaction_ios_number<P>(
Ok(())
}

pub(super) fn valid_transaction_date<P>(
settings: &setting::Settings,
tx: &TransactionSlice<P>,
date: BlockDate,
) -> Result<(), TxVerifyError> {
let valid_until = tx.valid_until();

// if current date epoch is less than until.epoch - setting, then
// the transaction has a validity range that is too big to be accepted
if_cond_fail_with!(
date.epoch
< valid_until
.epoch
.saturating_sub(settings.transaction_max_expiry_epochs.into()),
TxVerifyError::TransactionValidForTooLong
)?;
// if current date is passed the validity until, the transaction is expired
if_cond_fail_with!(date > valid_until, TxVerifyError::TransactionExpired)?;
Ok(())
}

#[cfg(test)]
mod tests {

Expand Down
Loading