Skip to content

Commit

Permalink
deploy to fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
Tguntenaar committed Dec 4, 2024
1 parent a79e0a9 commit 11d270c
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 72 deletions.

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

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

2 changes: 1 addition & 1 deletion bring-cache-up-to-date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests

local = True
reset_from_zero = False # False to continue from where it left off
reset_from_zero = True # False to continue from where it left off
fly_app_name = "devhub-cache-api-rs"
# ~120 calls for devhub
# ~20 calls for infra
Expand Down
85 changes: 63 additions & 22 deletions scripts/compare_indexers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,59 @@ const fetch_from_cache = async () => {
}
);
let json = await response.json();
// console.log(json);
return json;
};

const print_all_object_diffs = (cache_obj, pagoda_obj) => {
let differences = [];

Object.keys(cache_obj).forEach((key) => {
if (key === "views") {
return;
}
if (key === "labels") {
let cache_labels = cache_obj[key].length;
let pagoda_labels = pagoda_obj[key].length;
console.log("label types", cache_labels, pagoda_labels);

return;
}
if (key === "timeline") {
if (SKIP_TIMELINE) {
return;
}
if (cache_obj[key].status !== pagoda_obj[key].status) {
differences.push({
key,
cache: cache_obj[key],
pagoda: pagoda_obj[key],
block_height: cache_obj.block_height,
});
}
} else if (cache_obj[key] !== pagoda_obj[key]) {
differences.push({
key,
cache: cache_obj[key],
pagoda: pagoda_obj[key],
block_height: cache_obj.block_height,
});
}
});

if (differences.length > 0) {
console.log("\nFound differences:");
differences.forEach((diff) => {
console.log(` ${diff.key}:`);
console.log(` cache: `, diff.cache);
console.log(` pagoda: `, diff.pagoda);
console.log(` on block: ${diff.block_height}`);
});
console.log();
} else {
console.log(" No differences found");
}
};

const compare_results = async () => {
const cache_result = await fetch_from_cache();
const pagoda_result = await fetch_from_pagoda();
Expand All @@ -49,33 +98,25 @@ const compare_results = async () => {

let cache_total = cache_result.total_records;

// Check which proposals is not the same in both indexers
console.log(
"Proposals that are not the same in both indexers: ",
pagoda_records
.filter(
(p) =>
!cache_records.some(
(c) =>
JSON.parse(p.timeline).status === JSON.parse(c.timeline).status
)
)
.map((p) => p.proposal_id)
);
// console.log(
// "Pagoda ids: ",
// pagoda_records.map((p) => [p.proposal_id, JSON.parse(p.timeline).status])
// );
// console.log(
// "Cache ids: ",
// cache_records.map((c) => [c.proposal_id, JSON.parse(c.timeline).status])
// );

console.log(
"Pagoda ids: ",
pagoda_records.map((p) => [p.proposal_id, JSON.parse(p.timeline).status])
);
console.log(
"Cache ids: ",
cache_records.map((c) => [c.proposal_id, JSON.parse(c.timeline).status])
);
for (let i = 0; i < pagoda_records.length; i++) {
console.log(`proposal_id: ${pagoda_records[i].proposal_id} snapshot ${i}`);
print_all_object_diffs(pagoda_records[i], cache_records[i]);
}

console.log("pagoda_total, cache_total", pagoda_total, cache_total);
};

const LIMIT = 10;
const OFFSET = 10;
const SKIP_TIMELINE = false;

compare_results();
39 changes: 4 additions & 35 deletions src/nearblocks_client/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ pub async fn handle_set_block_height_callback(
db: &State<DB>,
contract: &AccountId,
) -> Result<(), Status> {
if !transaction.receipt_outcome.status {
eprintln!(
"Proposal receipt outcome status is {:?}",
transaction.receipt_outcome.status
);
eprintln!("On transaction: {:?}", transaction);
return Ok(());
}

let action = transaction
.actions
.as_ref()
Expand Down Expand Up @@ -66,8 +57,8 @@ pub async fn handle_set_block_height_callback(

let snapshot = ProposalSnapshotRecord::from_contract_proposal(
versioned_proposal.clone().into(),
transaction.receipt_block.block_timestamp,
transaction.receipt_block.block_height,
transaction.block_timestamp.parse::<i64>().unwrap(),
transaction.block.block_height,
);

DB::insert_proposal_snapshot(&mut tx, &snapshot)
Expand All @@ -85,17 +76,6 @@ pub async fn handle_set_block_height_callback(
Status::InternalServerError
})?;

// Handle linked proposals update
// let new_linked_rfp = snapshot.linked_rfp;
// update_linked_proposals(
// id,
// new_linked_rfp,
// transaction.receipt_block.block_height,
// transaction.receipt_block.block_timestamp,
// db,
// )
// .await?;

Ok(())
}

Expand Down Expand Up @@ -128,8 +108,8 @@ pub async fn handle_edit_proposal(

let snapshot = ProposalSnapshotRecord::from_contract_proposal(
versioned_proposal.clone().into(),
transaction.receipt_block.block_timestamp,
transaction.receipt_block.block_height,
transaction.block_timestamp.parse::<i64>().unwrap(),
transaction.block.block_height,
);

DB::insert_proposal_snapshot(&mut tx, &snapshot)
Expand All @@ -147,17 +127,6 @@ pub async fn handle_edit_proposal(
Status::InternalServerError
})?;

// Handle linked proposals update
// let new_linked_rfp = snapshot.linked_rfp;
// update_linked_proposals(
// id,
// new_linked_rfp,
// transaction.receipt_block.block_height,
// transaction.receipt_block.block_timestamp,
// db,
// )
// .await?;

Ok(())
}

Expand Down
19 changes: 5 additions & 14 deletions src/nearblocks_client/rfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ pub async fn handle_set_rfp_block_height_callback(
db: &State<DB>,
contract: &AccountId,
) -> Result<(), Status> {
if !transaction.receipt_outcome.status {
eprintln!(
"RFP receipt outcome status is {:?}",
transaction.receipt_outcome.status
);
eprintln!("On transaction: {:?}", transaction);
return Ok(());
}

let action = transaction
.actions
.as_ref()
Expand Down Expand Up @@ -56,8 +47,8 @@ pub async fn handle_set_rfp_block_height_callback(

let snapshot = RfpSnapshotRecord::from_contract_rfp(
versioned_rfp.into(),
transaction.receipt_block.block_timestamp,
transaction.receipt_block.block_height,
transaction.block_timestamp.parse::<i64>().unwrap(),
transaction.block.block_height,
);

DB::insert_rfp_snapshot(&mut tx, &snapshot).await.unwrap();
Expand Down Expand Up @@ -112,13 +103,13 @@ pub async fn handle_edit_rfp(
let contract_rfp: ContractRFP = versioned_rfp.clone().into();
println!(
"RFP {} timestamp {}",
contract_rfp.id, transaction.receipt_block.block_timestamp
contract_rfp.id, transaction.block_timestamp
);

let snapshot = RfpSnapshotRecord::from_contract_rfp(
versioned_rfp.into(),
transaction.receipt_block.block_timestamp,
transaction.receipt_block.block_height,
transaction.block_timestamp.parse::<i64>().unwrap(),
transaction.block.block_height,
);

DB::insert_rfp_snapshot(&mut tx, &snapshot)
Expand Down
8 changes: 8 additions & 0 deletions src/nearblocks_client/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ pub async fn process(
.as_ref()
.and_then(|actions| actions.first())
{
if !transaction.receipt_outcome.status {
eprintln!(
"Proposal receipt outcome status is {:?}",
transaction.receipt_outcome.status
);
eprintln!("On transaction: {:?}", transaction);
continue;
}
let result = match action.method.as_deref().unwrap_or("") {
"set_block_height_callback" => {
handle_set_block_height_callback(transaction.to_owned(), db, contract).await
Expand Down

0 comments on commit 11d270c

Please sign in to comment.