Skip to content
Merged
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
39 changes: 37 additions & 2 deletions src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ impl StacksChainState {
}

let mut allocation_events: Vec<StacksTransactionEvent> = vec![];
let mut lockup_events: Vec<StacksTransactionEvent> = vec![];

info!(
"Initializing chain with {} config balances",
boot_data.initial_balances.len()
Expand Down Expand Up @@ -1001,12 +1003,27 @@ impl StacksChainState {
.with_clarity_db(|db| {
for (block_height, schedule) in lockups_per_block.into_iter() {
let key = Value::UInt(block_height.into());
let value = Value::list_from(schedule).unwrap();
db.insert_entry(
&lockup_contract_id,
"lockups",
key,
Value::list_from(schedule).unwrap(),
key.clone(),
value.clone(),
)?;

// Attach some events
let lookup_event = TupleData::from_data(vec![
(ClarityName::try_from("block-height").unwrap(), key),
(ClarityName::try_from("due-schedules").unwrap(), value),
])
.unwrap();
let lookup_event = StacksTransactionEvent::SmartContractEvent(
SmartContractEventData {
key: (boot_code_id("lockup"), "print".to_string()),
value: Value::Tuple(lookup_event),
},
);
lockup_events.push(lookup_event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, these are all "synthetic" events -- they don't correspond to a real transaction on the blockchain. This could confuse users and block explorers -- they'll see a txid, but be unable to query it from the chainstate (we've had this problem before in Stacks 1.0 with "synthetic transactions" that achieved the same end).

Would it make sense to add a field in the StacksTransactionEvent struct to indicate whether or not the event came from a synthetic transaction, so people don't mistakenly believe that these genesis events correspond to on-chain transactions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to address it in this PR if you're pressed for time, but please do open an issue for it if you're not going to address it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, any insight into how big this list will be in RAM?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I share the concern about these transactions and events being odd one-offs, however, the event broadcaster attaches these to the initial block in a way that does not require any special handling by the sidecar/explorer. We've already been doing this for a while in order to get the boot contracts exposed in a normalized way.

I can imagine how an is_synthetic field could be useful, but I don't think it's worth the effort at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, any insight into how big this list will be in RAM?

It's a couple of megabytes on disk, not sure about the representation in RAM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing some benchmarks on memory usage

Copy link
Contributor

@zone117x zone117x Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR appears to increase max memory usage from ~580MB to ~700MB. Measured a few times with
time -l stacks-node mocknet and looking at the reported maximum resident set size.
Tests performed without an event observer configured.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound too bad.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also of note: with an event observer attached, memory usage is ~2.6GB. The content-size of the first block event payload is ~100MB.

}
Ok(())
})
Expand Down Expand Up @@ -1190,6 +1207,24 @@ impl StacksChainState {
);
receipts.push(allocations_receipt);

let lockup_tx = StacksTransaction::new(
tx_version.clone(),
boot_code_auth.clone(),
TransactionPayload::ContractCall(TransactionContractCall {
address: boot_code_address,
contract_name: ContractName::try_from("lockup").unwrap(),
function_name: ClarityName::try_from("genesis").unwrap(),
function_args: vec![],
}),
);
let lockup_receipt = StacksTransactionReceipt::from_stx_transfer(
lockup_tx,
lockup_events,
Value::okay_true(),
ExecutionCost::zero(),
);
receipts.push(lockup_receipt);

if let Some(callback) = boot_data.post_flight_callback.take() {
callback(&mut clarity_tx);
}
Expand Down