Open dan-da opened 4 hours ago
Regarding point 2, I'm pretty sure the culprit is in Utxo::can_spend_at
. Everytime we calculate the hash of a program, the program's assembler code is assembled and the resulting list of instructions hashed. Especially the assembling is expensive. The relevant trait implementations are on ConsensusProgram
:
/// Get the program as a `Program` object rather than as a list of `LabelledInstruction`s.
fn program(&self) -> Program {
Program::new(&self.code())
}
/// Get the program hash digest.
fn hash(&self) -> Digest {
self.program().hash()
}
But the hash
value never changes, as the implementations of ConsensusProgram
has no dynamic parameters. So we can change the implementation of hash
on a per-implementation level to be:
/// Cache for program hash, for faster claim production.
static PROGRAM_HASH: LazyLock<Digest> =
LazyLock::new(|| TransactionIsValid.program().hash());
And then overwrite the default implementation of hash
(or maybe even get entirely rid of it) to be:
impl ConsensusProgram for TransactionIsValid {
fn hash(&self) -> Digest {
*PROGRAM_HASH
}
Credit for this approach goes to @aszepieniec who implemented it for the now-deleted consensus program src/models/blockchain/block/validity/transaction_is_valid.rs
.
I have instrumented dashboard_overview_data() to log duration of most of the functions it calls.
Below are warnings from a recent invocation that lasted 4.3 seconds.
setup:
analysis: