Skip to content

Commit

Permalink
[graphql/rpc] change expiration field in tx block (#14147)
Browse files Browse the repository at this point in the history
## Description 

Use the available data for the expiration field instead of using the get
last system state.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
stefan-mysten authored Oct 6, 2023
1 parent 5d040e1 commit 440bb9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 7 additions & 1 deletion crates/sui-graphql-rpc/src/context_data/db_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use sui_sdk::types::{
CheckpointCommitment, CheckpointDigest, EndOfEpochData as NativeEndOfEpochData,
},
object::{Data, Object as SuiObject},
transaction::{SenderSignedData, TransactionDataAPI},
transaction::{SenderSignedData, TransactionDataAPI, TransactionExpiration},
};

#[derive(thiserror::Error, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -869,12 +869,18 @@ impl TryFrom<StoredTransaction> for TransactionBlock {
))),
}?;

let epoch_id = match sender_signed_data.intent_message().value.expiration() {
TransactionExpiration::None => None,
TransactionExpiration::Epoch(epoch_id) => Some(*epoch_id),
};

Ok(Self {
digest,
effects,
sender: Some(sender),
bcs: Some(Base64::from(&tx.raw_transaction)),
gas_input: Some(gas_input),
epoch_id,
})
}
}
Expand Down
25 changes: 15 additions & 10 deletions crates/sui-graphql-rpc/src/types/transaction_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::context_data::{
context_ext::DataProviderContextExt, sui_sdk_data_provider::convert_to_epoch,
context_ext::DataProviderContextExt, db_data_provider::PgManager,
sui_sdk_data_provider::convert_to_epoch,
};

use super::{
Expand All @@ -28,6 +29,8 @@ pub(crate) struct TransactionBlock {
pub sender: Option<Address>,
pub bcs: Option<Base64>,
pub gas_input: Option<GasInput>,
#[graphql(skip)]
pub epoch_id: Option<u64>,
}

impl From<SuiTransactionBlockResponse> for TransactionBlock {
Expand All @@ -44,6 +47,7 @@ impl From<SuiTransactionBlockResponse> for TransactionBlock {
sender,
bcs: Some(Base64::from(&tx_block.raw_transaction)),
gas_input,
epoch_id: None,
}
}
}
Expand All @@ -55,16 +59,17 @@ impl TransactionBlock {
}

async fn expiration(&self, ctx: &Context<'_>) -> Result<Option<Epoch>> {
if self.effects.is_none() {
return Ok(None);
match self.epoch_id {
None => Ok(None),
Some(epoch_id) => {
let epoch = ctx
.data_unchecked::<PgManager>()
.fetch_epoch_strict(epoch_id)
.await
.extend()?;
Ok(Some(epoch))
}
}
let gcs = self.effects.as_ref().unwrap().gas_effects.gcs;
// TODO: implement DB counterpart without using Sui SDK client
let data_provider = ctx.data_provider();
let system_state = data_provider.get_latest_sui_system_state().await?;
let protocol_configs = data_provider.fetch_protocol_config(None).await?;
let epoch = convert_to_epoch(gcs, &system_state, &protocol_configs)?;
Ok(Some(epoch))
}
}

Expand Down

1 comment on commit 440bb9b

@vercel
Copy link

@vercel vercel bot commented on 440bb9b Oct 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.