Skip to content

Add Alkanes#8

Open
subfrostdev wants to merge 26 commits intoSaturnBTC:masterfrom
subfrost:wasm
Open

Add Alkanes#8
subfrostdev wants to merge 26 commits intoSaturnBTC:masterfrom
subfrost:wasm

Conversation

@subfrostdev
Copy link
Copy Markdown

Imports metashrew-runtime v9.0.1 for latest stable wasmtime environment to run ./vendor/alkanes.wasm built from latest tagged release (v2.1.4)

Includes in BlockCache updater k/v flush from alkanes per block, into ALKANES_CF.

Extends REST API of Titan and translates between REST/JSON to protobuf types for indexer view APIs.

Copy link
Copy Markdown
Contributor

@macols77 macols77 left a comment

Choose a reason for hiding this comment

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

Thanks for this feature! Impressive work and it's a very clean way of implementing it but could you take a look at the comments I left whenever you have some time?

Thanks a lot!

.with_label_values(&["index_block"])
.start_timer();

self.alkanes_indexer.lock().unwrap().index_block(&bitcoin_block, height);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you return UpdaterError::Mutex error instead of unwrap?

Comment thread indexer/src/alkanes/indexer.rs Outdated
}

pub fn index_block(&mut self, block: &BitcoinBlock, height: u64) {
let mut context = self.runtime.context.lock().unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove unwraps please

Comment thread indexer/src/api/alkanes.rs Outdated
}),
};
let mut payload = Vec::new();
request.encode(&mut payload).unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

avoid unwraps please

use std::any::Any;

pub trait Store: std::fmt::Debug + Any {
fn as_any(&self) -> &dyn Any;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove this

impl Updater {
pub fn new(
db: Arc<dyn Store + Send + Sync>,
db: Arc<crate::db::RocksDB>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

revert this

shutdown_flag: Arc<AtomicBool>,
sender: Option<Sender<Event>>,
) -> Self {
let alkanes_indexer = Mutex::new(AlkanesIndexer::new(db.clone()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's better to pass the alkanes_indexer as parameter rather than changing the db type.

Comment thread indexer/src/main.rs Outdated
));
index.validate_index()?;

let alkanes_indexer = Arc::new(alkanes::indexer::AlkanesIndexer::new(db_arc.clone()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alkanes should be optional. Use the options.rs

Comment thread indexer/src/db/rocks.rs Outdated
Ok(())
}

pub fn put_cf<K: AsRef<[u8]>, V: AsRef<[u8]>>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you need this set of methods in the rocksdb if you've created a add_misc_batch in the block cache?

subfrostdev and others added 2 commits October 21, 2025 18:09
@subfrostdev
Copy link
Copy Markdown
Author

Merged subfrost/Titan#1



#[derive(Deserialize)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you fix lint here please? run cargo fmt

Comment thread indexer/src/index/index.rs Outdated

pub struct Index {
db: Arc<dyn Store + Send + Sync>,
db: Arc<RocksDB>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are you removing the Store interface?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It requires a downcast to construct the AlkanesIndexer I wrote so I can either have the downcast or I can update AlkanesIndexer to use the StoreWithLock type.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The traits in MetashrewRuntime for KeyValueStoreLike relies on RocksDB specific methods, particularly iterator_cf, which doesn't really get used by alkanes.wasm anyway.

Either way, it is simplest just to downcast, so I will reintroduce that.

for (i, tx) in bitcoin_block.txdata.iter().enumerate() {
let txid = tx.compute_txid().into();
match transaction_parser.parse(cache, u32::try_from(i).unwrap(), tx) {
match transaction_parser.parse(cache, u32::try_from(i).map_err(|_| UpdaterError::Mutex)?, tx) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This unwrap is not a mutex. It's safe to unwrap since it's a u32 and there is no way a bitcoin block can have more than u32::MAX.

I'd rather do:

match transaction_parser.parse(cache, u32::try_from(i).expect("transaction index exceeds u32::MAX"), tx)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants