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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ name: CI

on:
pull_request:
paths:
- 'listener/src/migrations/**'
- 'listener/src/database/**'
- 'listener/src/scripts/**'
- 'listener/package.json'
push:
branches:
- main
- staging

jobs:
frontend:
Expand Down Expand Up @@ -61,6 +70,29 @@ jobs:
working-directory: listener
run: npm test --silent

check-migrations:
name: Check Pending Migrations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: listener/package-lock.json
- name: Install dependencies
working-directory: listener
run: npm ci
- name: Create test database and apply all migrations
working-directory: listener
run: |
mkdir -p ./data
npm run migrate
- name: Check for pending migrations
working-directory: listener
run: npm run check-migrations

rust:
name: Rust (fmt check, tests, fuzz)
runs-on: ubuntu-latest
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ on:
branches:
- staging
jobs:
check-migrations:
name: Check Pending Migrations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: |
cd listener
npm ci
mkdir -p ./data
npm run migrate
npm run check-migrations

deploy:
runs-on: ubuntu-latest
needs: check-migrations
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
39 changes: 39 additions & 0 deletions contract/contracts/hello-world/EVENT_GAS_OPTIMIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Event Gas Optimization

This commit optimizes event emissions by removing redundant timestamp fields that can be derived from ledger metadata.

## Changes Made

### 1. `AuditRecordAppended` Event
- **Removed**: `timestamp` field
- **Rationale**: The timestamp of event emission is already available in the ledger metadata for every event
- **Savings**: ~8 bytes per event

### 2. `NotificationRevoked` Event
- **Removed**: `revoked_at` field
- **Rationale**: The timestamp of revocation is already available in the ledger metadata for the event
- **Savings**: ~8 bytes per event

## Files Modified

1. `src/base/events.rs`:
- Updated `AuditRecordAppended` to remove timestamp field
- Updated `NotificationRevoked` to remove revoked_at field
- Added comments explaining the gas optimization rationale

2. `src/autoshare_logic.rs`:
- Updated `append_audit_record` to remove timestamp from event emission
- Updated `revoke_notification` to remove revoked_at from event emission

## Notes

- The `AuditRecord` stored in contract state still retains the `timestamp` field for on-chain audit purposes
- All existing tests pass (no test changes required as we only modified event emission, not stored state)
- Off-chain consumers can still obtain the timestamp from the ledger transaction metadata

## Verification

These changes follow the gas optimization best practice of avoiding redundant data in event emissions, since:
1. Every event already has a timestamp in the ledger context
2. Storing redundant data in events increases gas costs without providing additional value
3. The changes maintain backward compatibility for all other event fields
2 changes: 0 additions & 2 deletions contract/contracts/hello-world/src/autoshare_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,6 @@ pub fn revoke_notification(
revoked_by: caller,
category: NotificationCategory::Notification,
priority: NotificationPriority::High,
revoked_at,
}
.publish(&env);

Expand Down Expand Up @@ -1362,7 +1361,6 @@ fn append_audit_record(
category: NotificationCategory::Notification,
seq,
actor,
timestamp,
}
.publish(env);
}
Expand Down
8 changes: 4 additions & 4 deletions contract/contracts/hello-world/src/base/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub struct AuditRecordAppended {
pub category: NotificationCategory,
pub seq: u64,
pub actor: Address,
pub timestamp: u64,
// GAS: Removed `timestamp` — derivable from ledger metadata
}

/// Emitted when a batch of notifications is created in a single transaction.
Expand All @@ -297,8 +297,8 @@ pub struct BatchNotificationsCreated {
///
/// The `notification_id` is published as an indexed topic so consumers can
/// subscribe to the revocation of a specific notification; the `revoked_by`
/// address indicates who initiated the revocation, and `revoked_at` records
/// the ledger timestamp when the revocation occurred.
/// address indicates who initiated the revocation. The timestamp when the
/// revocation occurred is derivable from ledger metadata.
#[contractevent(data_format = "single-value")]
#[derive(Clone)]
pub struct NotificationRevoked {
Expand All @@ -310,7 +310,7 @@ pub struct NotificationRevoked {
pub category: NotificationCategory,
#[topic]
pub priority: NotificationPriority,
pub revoked_at: u64,
// GAS: Removed `revoked_at` — derivable from ledger metadata
}

/// Emitted when a scheduled notification's expiry period is extended by an authorized sender.
Expand Down
Loading
Loading