Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two phase commit for mobile packet verifier #700

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions mobile_packet_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "sol
metrics = {workspace = true}
poc-metrics = {path = "../metrics"}
prost = {workspace = true}
solana-sdk = {workspace = true}
serde = {workspace = true}
sqlx = {workspace = true}
solana = {path = "../solana"}
Expand Down
29 changes: 29 additions & 0 deletions mobile_packet_verifier/migrations/7_two_phase_commit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE TABLE pending_txns AS (
signature TEXT PRIMARY KEY,
pub_key TEXT NOT NULL,
payer TEXT NOT NULL,
num_dcs BIGINT NOT NULL,
uploaded_bytes BIGINT NOT NULL,
downloaded_bytes BIGINT NOT NULL,
rewardable_bytes BIGINT NOT NULL,
first_timestamp TIMESTAMPTZ NOT NULL,
last_timestmap TIMESTAMPTZ NOT NULL
);

CREATE TABLE data_transfer_sessions_by_row (
pub_key TEXT NOT NULL,
payer TEXT NOT NULL,
uploaded_bytes BIGINT NOT NULL,
downloaded_bytes BIGINT NOT NULL,
rewardable_bytes BIGINT NOT NULL,
session_timestamp TIMESTAMPTZ NOT NULL,
PRIMARY KEY(pub_key, payer, session_timestamp)
);

INSERT INTO data_transfer_sessions_by_row
(pub_key, payer, uploaded_bytes, downloaded_bytes, rewardable_bytes, session_timestamp)
SELECT pub_key, payer, uploaded_bytes, downloaded_bytes, rewardable_bytes, last_timestamp as session_timestamp FROM data_transfer_sessions;

ALTER TABLE data_transfer_sessions RENAME TO old_data_transfer_sessions;
ALTER TABLE data_transfer_sessions_by_row to data_transfer_sessions;
DROP TABLE data_transfer_sessions;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you mean DROP TABLE old_data_transfer_sessions?

10 changes: 2 additions & 8 deletions mobile_packet_verifier/src/accumulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ pub async fn accumulate_sessions(
let event = report.report.data_transfer_usage;
sqlx::query(
r#"
INSERT INTO data_transfer_sessions (pub_key, payer, uploaded_bytes, downloaded_bytes, rewardable_bytes, first_timestamp, last_timestamp)
VALUES ($1, $2, $3, $4, $5, $6, $6)
ON CONFLICT (pub_key, payer) DO UPDATE SET
uploaded_bytes = data_transfer_sessions.uploaded_bytes + EXCLUDED.uploaded_bytes,
downloaded_bytes = data_transfer_sessions.downloaded_bytes + EXCLUDED.downloaded_bytes,
rewardable_bytes = data_transfer_sessions.rewardable_bytes + EXCLUDED.rewardable_bytes,
last_timestamp = GREATEST(data_transfer_sessions.last_timestamp, EXCLUDED.last_timestamp)
INSERT INTO data_transfer_sessions (pub_key, payer, uploaded_bytes, downloaded_bytes, rewardable_bytes, session_timestamp) VALUES ($1, $2, $3, $4, $5, $6);
"#
)
.bind(event.pub_key)
.bind(event.payer)
.bind(&event.payer)
.bind(event.upload_bytes as i64)
.bind(event.download_bytes as i64)
.bind(report.report.rewardable_bytes as i64)
Expand Down
Loading
Loading