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

fix: spade oracle sync with log2size to height conversion #78

Merged
merged 4 commits into from
Nov 14, 2023
Merged
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
8 changes: 5 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@ucanto/server": "^9.0.1",
"@ucanto/transport": "^9.0.0",
"@web3-storage/capabilities": "^11.1.0",
"@web3-storage/data-segment": "^4.0.0",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/filecoin-api": "^4.0.4",
"@web3-storage/filecoin-client": "^3.0.1",
"fzstd": "^0.1.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/deal-tracker/spade-oracle-sync-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async function fetchLatestDealArchive (spadeOracleUrl) {
// Convert PieceCidV1 to PieceCidV2
const pieceCid = convertPieceCidV1toPieceCidV2(
parseLink(replica.piece_cid),
replica.piece_log2_size
log2PieceSizeToHeight(replica.piece_log2_size)
)
dealMap.set(pieceCid.toString(), replica.contracts.map(c => ({
provider: c.provider_id,
Expand Down Expand Up @@ -239,3 +239,11 @@ export function convertPieceCidV1toPieceCidV2 (link, height) {

return piece.link
}

/**
*
* @param {number} log2Size
*/
export function log2PieceSizeToHeight (log2Size) {
return Piece.Size.Expanded.toHeight(2n ** BigInt(log2Size))
}
4 changes: 4 additions & 0 deletions packages/core/test/deal-tracker/spade-oracle-sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ test('converts PieceCidV1 to PieceCidV2', t => {
t.falsy(pieceCidV1.equals(pieceCidV2))
})

test('converts log2pieceSize to height', t => {
const height = spadeOracleSyncTick.log2PieceSizeToHeight(35)
t.is(height, 30)
})
/**
* @param {string} source
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function getLambdaEnv () {
return {
did: mustGetEnv('DID'),
ucanLogUrl: mustGetEnv('UCAN_LOG_URL'),
dealStoreTableName: Table['deal-tracker-deal-store'],
dealStoreTableName: Table['deal-tracker-deal-store-v1'],
dealStoreTableRegion: mustGetEnv('AWS_REGION'),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getLambdaEnv () {
return {
dealArchiveStoreBucketName: mustGetEnv('DEAL_ARCHIVE_STORE_BUCKET_NAME'),
dealArchiveStoreBucketRegion: mustGetEnv('DEAL_ARCHIVE_STORE_REGION'),
dealStoreTableName: Table['deal-tracker-deal-store'],
dealStoreTableName: Table['deal-tracker-deal-store-v1'],
dealStoreTableRegion: mustGetEnv('AWS_REGION'),
spadeOracleUrl: mustGetEnv('SPADE_ORACLE_URL'),
}
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare module 'sst/node/table' {
'aggregator-inclusion-store': {
tableName: string;
};
'deal-tracker-deal-store': {
'deal-tracker-deal-store-v1': {
tableName: string;
};
'dealer-aggregate-store': {
Expand Down
4 changes: 2 additions & 2 deletions stacks/data-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function DataStack({ stack, app }) {
/**
* Deal archive store used to store active replicas reported by Spade Oracle.
*/
const dealTrackerDealArchiveBucket = getBucketConfig('deal-tracker-deal-archive-store', stack.stage)
const dealTrackerDealArchiveBucket = getBucketConfig('deal-tracker-deal-archive-store', stack.stage, 1)
const dealTrackerDealArchiveStoreBucket = new Bucket(stack, dealTrackerDealArchiveBucket.bucketName, {
cors: true,
cdk: {
Expand All @@ -123,7 +123,7 @@ export function DataStack({ stack, app }) {
/**
* Deal store used to store deal information
*/
const dealTrackerDealStoreTableName = 'deal-tracker-deal-store'
const dealTrackerDealStoreTableName = 'deal-tracker-deal-store-v1'
const dealTrackerDealStoreTable = new Table(stack, dealTrackerDealStoreTableName, {
...dealStoreTableProps,
// information that will be written to the stream
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const getStoreClients = () => {
},
tracker: {
dealStore: createDealTrackerDealStoreClient(dynamoClient,
{ tableName: getTableName(`deal-tracker-deal-store`) }
{ tableName: getTableName(`deal-tracker-deal-store-v1`) }
)
}
}
Expand Down
Loading