mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-28 22:51:04 +03:00
kns: add final tweaks
This commit is contained in:
parent
17e97a35a9
commit
79b00c4c26
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3504,12 +3504,12 @@ dependencies = [
|
|||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-sol-types",
|
"alloy-sol-types",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bincode",
|
|
||||||
"hex",
|
"hex",
|
||||||
"kinode_process_lib 0.9.0 (git+https://github.com/kinode-dao/process_lib?rev=64b4d9e)",
|
"kinode_process_lib 0.9.0 (git+https://github.com/kinode-dao/process_lib?rev=64b4d9e)",
|
||||||
"rmp-serde",
|
"rmp-serde",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
"wit-bindgen",
|
"wit-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@ simulation-mode = []
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
alloy-primitives = "0.7.0"
|
alloy-primitives = "0.7.0"
|
||||||
alloy-sol-types = "0.7.0"
|
alloy-sol-types = "0.7.0"
|
||||||
bincode = "1.3.3"
|
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "64b4d9e" }
|
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "64b4d9e" }
|
||||||
rmp-serde = "1.1.2"
|
rmp-serde = "1.1.2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
thiserror = "1.0"
|
||||||
wit-bindgen = "0.24.0"
|
wit-bindgen = "0.24.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -58,6 +58,12 @@ enum IndexerResponses {
|
|||||||
GetState(State),
|
GetState(State),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
enum KnsError {
|
||||||
|
#[error("Parent node for note not found")]
|
||||||
|
NoParentError,
|
||||||
|
}
|
||||||
|
|
||||||
call_init!(init);
|
call_init!(init);
|
||||||
fn init(our: Address) {
|
fn init(our: Address) {
|
||||||
println!("indexing on contract address {KIMAP_ADDRESS}");
|
println!("indexing on contract address {KIMAP_ADDRESS}");
|
||||||
@ -324,21 +330,34 @@ fn handle_pending_notes(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut blocks_to_remove = vec![];
|
let mut blocks_to_remove = vec![];
|
||||||
let mut notes_to_retry = Vec::new();
|
|
||||||
|
|
||||||
for (block, notes) in pending_notes.iter_mut() {
|
for (block, notes) in pending_notes.iter_mut() {
|
||||||
if *block < state.last_block {
|
if *block < state.last_block {
|
||||||
let mut keep_notes = Vec::new();
|
let mut keep_notes = Vec::new();
|
||||||
for (note, attempt) in notes.drain(..) {
|
for (note, attempt) in notes.drain(..) {
|
||||||
if attempt >= MAX_PENDING_ATTEMPTS {
|
if attempt >= MAX_PENDING_ATTEMPTS {
|
||||||
continue; // skip notes that have exceeded max attempts
|
// skip notes that have exceeded max attempts
|
||||||
}
|
|
||||||
if let Err(e) = handle_note(state, ¬e) {
|
|
||||||
print_to_terminal(
|
print_to_terminal(
|
||||||
1,
|
1,
|
||||||
&format!("pending note handling error! {e:?}, attempt {attempt}"),
|
&format!("dropping note from block {block} after {attempt} attempts"),
|
||||||
);
|
);
|
||||||
keep_notes.push((note, attempt + 1));
|
continue;
|
||||||
|
}
|
||||||
|
if let Err(e) = handle_note(state, ¬e) {
|
||||||
|
match e.downcast_ref::<KnsError>() {
|
||||||
|
None => {
|
||||||
|
print_to_terminal(1, &format!("pending note handling error: {e:?}"))
|
||||||
|
}
|
||||||
|
Some(ee) => match ee {
|
||||||
|
KnsError::NoParentError => {
|
||||||
|
print_to_terminal(
|
||||||
|
1,
|
||||||
|
&format!("note still awaiting mint; attempt {attempt}"),
|
||||||
|
);
|
||||||
|
keep_notes.push((note, attempt + 1));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if keep_notes.is_empty() {
|
if keep_notes.is_empty() {
|
||||||
@ -354,14 +373,6 @@ fn handle_pending_notes(
|
|||||||
pending_notes.remove(&block);
|
pending_notes.remove(&block);
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-insert notes that need to be retried
|
|
||||||
for (block, note, attempt) in notes_to_retry {
|
|
||||||
pending_notes
|
|
||||||
.entry(block)
|
|
||||||
.or_default()
|
|
||||||
.push((note, attempt));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +385,7 @@ fn handle_note(state: &mut State, note: &kimap::contract::Note) -> anyhow::Resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Some(node_name) = get_parent_name(&state.names, &node_hash) else {
|
let Some(node_name) = get_parent_name(&state.names, &node_hash) else {
|
||||||
return Err(anyhow::anyhow!("parent node for note not found"));
|
return Err(KnsError::NoParentError.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
match note_label.as_str() {
|
match note_label.as_str() {
|
||||||
@ -484,13 +495,19 @@ fn handle_log(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = handle_note(state, &decoded) {
|
if let Err(e) = handle_note(state, &decoded) {
|
||||||
print_to_terminal(1, &format!("note-handling error! {e:?}"));
|
match e.downcast_ref::<KnsError>() {
|
||||||
// If handling fails (likely due to parent not found), add to pending_notes
|
None => print_to_terminal(1, &format!("note handling error: {e:?}")),
|
||||||
if let Some(block_number) = log.block_number {
|
Some(ee) => match ee {
|
||||||
pending_notes
|
KnsError::NoParentError => {
|
||||||
.entry(block_number)
|
print_to_terminal(1, &format!("note awaiting mint: place in pending"));
|
||||||
.or_default()
|
if let Some(block_number) = log.block_number {
|
||||||
.push((decoded, 0));
|
pending_notes
|
||||||
|
.entry(block_number)
|
||||||
|
.or_default()
|
||||||
|
.push((decoded, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user