Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Added sync route, cache offset param (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLoneRonin authored May 24, 2021
1 parent ea003f4 commit eab7932
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ MAX_PAGE_SIZE=100
INDICES=["App-Name", "app", "domain", "namespace"]

CACHING=1
CACHE_FOLDER=/gateway/cache
CACHE_FOLDER=/gateway/cache
CACHE_OFFSET=0
3 changes: 2 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ MAX_PAGE_SIZE=100
INDICES=["App-Name", "app", "domain", "namespace"]

CACHING=1
CACHE_FOLDER=/gateway/cache
CACHE_FOLDER=/gateway/cache
CACHE_OFFSET=0
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ INDICES=["App-Name", "app", "domain", "namespace"]
CACHING=1
CACHE_FOLDER=/gateway/cache
CACHE_OFFSET=0
```

Make sure you copy this configuration to `.env`.
Expand Down
1 change: 1 addition & 0 deletions docs/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ INDICES=["App-Name", "app", "domain", "namespace"]
CACHING=1
CACHE_FOLDER=/gateway/cache
CACHE_OFFSET=0
```

Make sure you copy this configuration to `.env`.
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ INDICES=["App-Name", "app", "domain", "namespace"]
CACHING=1
CACHE_FOLDER=/gateway/cache
CACHE_OFFSET=0
```

Make sure you copy this configuration to `.env`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arweave/gateway",
"version": "0.11.0",
"version": "0.11.1",
"main": "dist/src/Gateway.js",
"repository": "[email protected]:ArweaveTeam/gateway.git",
"author": "Arweave <[email protected]>",
Expand Down
2 changes: 2 additions & 0 deletions src/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {log} from './utility/log.utility';
import {sessionMiddleware, sessionPinningMiddleware} from './utility/session.utility';
import {graphServer} from './graphql/server.graphql';
import {statusRoute} from './route/status.route';
import {syncRoute} from './route/sync.route';
import {proxyRoute} from './route/proxy.route';
import {dataRouteRegex, dataHeadRoute, dataRoute} from './route/data.route';
import {peerRoute} from './route/peer.route';
Expand All @@ -29,6 +30,7 @@ export function start() {
app.use(koiLogger.logger);

app.get('/', statusRoute);
app.get('/status', syncRoute);

app.head(dataRouteRegex, dataHeadRoute);
app.get(dataRouteRegex, dataRoute);
Expand Down
8 changes: 5 additions & 3 deletions src/caching/ans.verify.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'colors';
import {config} from 'dotenv';
import {connection} from '../database/connection.database';
import {toB64url} from '../query/transaction.query';
import {cacheAnsFile} from './file.caching';

config();

const startingOffset = parseInt(process.env.CACHE_OFFSET || '0');
const name = toB64url('Bundle-Type');
const value = toB64url('ANS-102');

export async function ansVerify(offset: number = 0, parallelization: number = 4) {
console.log(name, value);

export async function ansVerify(offset: number = startingOffset, parallelization: number = 4) {
const query = await connection
.queryBuilder()
.select('*')
Expand Down
4 changes: 3 additions & 1 deletion src/route/status.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ export const start = Number(new Date);
export async function statusRoute(req: Request, res: Response) {
const info = await getNodeInfo();

const delta = info.height - currentHeight;

return res.status(200).send({
status: 'OK',
gatewayHeight: currentHeight,
arweaveHeight: info.height,
delta: info.height - currentHeight,
delta,
});
}
19 changes: 19 additions & 0 deletions src/route/sync.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Request, Response} from 'express';
import {currentHeight} from '../database/sync.database';
import {getNodeInfo} from '../query/node.query';

export const start = Number(new Date);

export async function syncRoute(req: Request, res: Response) {
const info = await getNodeInfo();

const delta = info.height - currentHeight;
const status = delta < 3 ? 200 : 400;

return res.status(status).send({
status: 'OK',
gatewayHeight: currentHeight,
arweaveHeight: info.height,
delta,
});
}

0 comments on commit eab7932

Please sign in to comment.