Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #96 from ar-io/PE-5458-blocklist-contract-evaluation
Browse files Browse the repository at this point in the history
chore(README): update README and rename env variable to match others, add to Swagger
  • Loading branch information
dtfiedler authored Jan 18, 2024
2 parents 2f86adf + 63aba2a commit 64f906b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ The service can be configured using environment variables. The following environ
- `GATEWAY_HOST`: the gateway used to evaluate Smartcontract state.
- `LOG_LEVEL`: the log level to display (using [Winston] log levels - e.g. `info`, `debug`)
- `LOG_FORMAT`: the log format to use when printing logs (e.g. `json`, `simple`)
- `PREFETCH_CONTRACTS`: boolean to enable/disable prefetching of contracts on startup. Defaults to `true`.
- `PREFETCH_CONTRACT_IDS`: comma separated list of contract IDs to prefetch on startup
- `ARNS_CONTRACT_TX_ID`: the ArNS contract transaction ID. Defaults to `bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U` and when `PREFETCH_CONTRACTS` is `true`, will be prefetched on startup.
- `BOOTSTRAP_CACHE`: loads warp cache from S3 on startup. Defaults to `false`.
- `BLOCKLISTED_CONTRACT_IDS`: comma separated list of contract IDs to block evaluation. These contracts will return `403` when requested.

You can `cp .env.sample .env` and modify them locally.

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
GATEWAY_PORT: ${GATEWAY_PORT:-1984}
GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http}
PREFETCH_CONTRACTS: ${PREFETCH_CONTRACTS:-false}
BLOCKLISTED_CONTRACTS: ${BLOCKLISTED_CONTRACTS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
BLOCKLISTED_CONTRACT_IDS: ${BLOCKLISTED_CONTRACT_IDS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
ports:
- '3000:3000'

Expand All @@ -34,7 +34,7 @@ services:
GATEWAY_HOST: ${GATEWAY_HOST:-arlocal}
GATEWAY_PORT: ${GATEWAY_PORT:-1984}
GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http}
BLOCKLISTED_CONTRACTS: ${BLOCKLISTED_CONTRACTS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
BLOCKLISTED_CONTRACT_IDS: ${BLOCKLISTED_CONTRACT_IDS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
depends_on:
- arlocal
- arns-service
31 changes: 29 additions & 2 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ components:
schema:
type: string
example: 'Internal server error'
BlocklistedContract:
description: The requested contract is blocklisted.
content:
application/json:
schema:
type: string
example: 'Contract is blocklisted'
schemas:
ArNsContractState:
type: object
Expand Down Expand Up @@ -198,6 +205,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -235,6 +244,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -299,6 +310,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -333,6 +346,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -384,6 +399,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -439,6 +456,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -476,6 +495,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -511,6 +532,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down Expand Up @@ -563,15 +586,17 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
$ref: '#/components/responses/InternalServerError'

/wallet/{walletAddress}/contracts:
get:
summary: Returns the contracts deployed, transferred to, or controlled by by a given wallet address
description: Returns the contracts deployed, transferred to, or controlled by by a given wallet address
summary: Returns the contracts deployed, transferred to, or controlled by by a given wallet address, excluding any blocklisted contracts.
description: Returns the contracts deployed, transferred to, or controlled by by a given wallet address, excluding any blocklisted contracts.
parameters:
- $ref: '#/components/parameters/walletAddress'
responses:
Expand Down Expand Up @@ -657,6 +682,8 @@ paths:
$ref: '#/components/schemas/EvaluationOptions'
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/BlocklistedContract'
'404':
$ref: '#/components/responses/NotFound'
'503':
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { EvaluationOptions } from 'warp-contracts';

export const PREFETCH_CONTRACTS = process.env.PREFETCH_CONTRACTS === 'true';
export const BOOTSTRAP_CACHE = process.env.BOOTSTRAP_CACHE === 'true';
export const BLOCKLISTED_CONTRACTS = process.env.BLOCKLISTED_CONTRACTS
? process.env.BLOCKLISTED_CONTRACTS.split(',')
export const BLOCKLISTED_CONTRACT_IDS = process.env.BLOCKLISTED_CONTRACT_IDS
? process.env.BLOCKLISTED_CONTRACT_IDS.split(',')
: ['fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ'];
export const ARWEAVE_TX_ID_REGEX = '([a-zA-Z0-9-_s+]{43})';
export const ARNS_NAME_REGEX = '([a-zA-Z0-9-s+]{1,51})';
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/blocklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Next } from 'koa';
import { BLOCKLISTED_CONTRACTS } from '../constants';
import { BLOCKLISTED_CONTRACT_IDS } from '../constants';
import { KoaContext } from '../types';
import logger from '../logger';
import { blockListedContractCount } from '../metrics';

export async function blocklistMiddleware(ctx: KoaContext, next: Next) {
const { contractTxId } = ctx.params;
if (BLOCKLISTED_CONTRACTS.includes(contractTxId)) {
if (BLOCKLISTED_CONTRACT_IDS.includes(contractTxId)) {
blockListedContractCount
.labels({
contractTxId,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../api/graphql';
import { isValidContractType, validateStateAndOwnership } from '../api/warp';
import {
BLOCKLISTED_CONTRACTS,
BLOCKLISTED_CONTRACT_IDS,
DEFAULT_STATE_EVALUATION_TIMEOUT_MS,
allowedContractTypes,
} from '../constants';
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function walletContractHandler(ctx: KoaContext) {
await Promise.allSettled(
[...deployedOrOwned].map(async (id: string) => {
// do not evaluate any blocklisted contracts
if (BLOCKLISTED_CONTRACTS.includes(id)) {
if (BLOCKLISTED_CONTRACT_IDS.includes(id)) {
logger.debug('Skipping blocklisted contract.', {
contractTxId: id,
});
Expand Down
11 changes: 6 additions & 5 deletions tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Integration tests', () => {
describe('/contract', () => {
describe('/:contractTxId', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}`,
);
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('Integration tests', () => {
});
describe('/:contractTxId/price', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/price`,
);
Expand All @@ -262,7 +262,7 @@ describe('Integration tests', () => {

describe('/:contractTxId/interactions', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/interactions`,
);
Expand Down Expand Up @@ -418,7 +418,8 @@ describe('Integration tests', () => {
'reserved',
]) {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId =
process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/${field}`,
);
Expand Down Expand Up @@ -693,7 +694,7 @@ describe('Integration tests', () => {

describe('/:address/contracts/:contractTxId', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/wallet/${walletAddress}/contract/${blocklistedContractTxId}`,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export async function mochaGlobalSetup() {
process.env.DEPLOYED_ANT_CONTRACT_TX_ID = antContractTxId;

// blocklisted contract
process.env.BLOCKLISTED_CONTRACTS =
process.env.BLOCKLISTED_CONTRACTS ||
process.env.BLOCKLISTED_CONTRACT_IDS =
process.env.BLOCKLISTED_CONTRACT_IDS ||
'fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ';
console.log(
`Successfully setup ArLocal and deployed contracts.\nRegistry: ${contractTxId}\nANT: ${antContractTxId}`,
Expand Down

0 comments on commit 64f906b

Please sign in to comment.