Skip to content
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

4 changes: 3 additions & 1 deletion crates/store/src/localdb/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ impl StorageProcessor<'_> {
Ok(res.rows_affected())
}

/// Stores `reward` as the node's new total; the caller has already added
/// the increment.
// Do not update the `updated_at` field; this field is updated based on heartbeat messages
// and is used to determine whether a node is alive.
pub async fn update_node_reward_by_peer_id(
&mut self,
peer_id: &str,
reward: &str,
) -> anyhow::Result<()> {
sqlx::query!(r#"UPDATE node SET reward = reward + ? WHERE peer_id = ?"#, reward, peer_id)
sqlx::query!(r#"UPDATE node SET reward = ? WHERE peer_id = ?"#, reward, peer_id)
.execute(self.conn())
.await?;
Ok(())
Expand Down
18 changes: 18 additions & 0 deletions node/src/scheduled_tasks/event_watch/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,24 @@ mod tests {
}
}

#[tokio::test]
async fn node_reward_is_added_once() {
let (db, _dir) = db().await;
let mut storage = db.acquire().await.unwrap();
let node = store::Node {
peer_id: "operator".into(),
goat_addr: "0xabc".into(),
..Default::default()
};
storage.upsert_node(&node).await.unwrap();
for _ in 0..2 {
add_node_reward(&mut storage, "0xabc", U256::from(5)).await.unwrap();
}
let nodes = storage.find_nodes(&NodeQuery::default()).await.unwrap().0;
// Adding the increment in SQL as well would give 0 + 5, then 5 + 10.
assert_eq!(nodes[0].reward, "10");
}

#[tokio::test]
async fn a_posted_graph_unknown_locally_is_pulled_by_the_watching_roles() {
let (db, _dir) = db().await;
Expand Down
Loading