Skip to content

Commit

Permalink
Remove Bee debug endpoint (deprecated in v2.1.0) (#410)
Browse files Browse the repository at this point in the history
* Remove Bee debug endpoint (deprecated in v2.1.0)

* fix some typos

* chore: add changeset

---------

Co-authored-by: PJColombo <[email protected]>
  • Loading branch information
PabloCastellano and PJColombo authored Jun 18, 2024
1 parent baa836b commit 28da372
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-pumpkins-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/blob-storage-manager": patch
---

Dropped bee debug client
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ INDEXER_TAG=master

EXTERNAL_WEB_PORT=3000

# BEE_DEBUG_ENDPOINT=
# BEE_ENDPOINT=

CHAIN_ID=1
Expand Down
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ GOOGLE_STORAGE_API_ENDPOINT=http://localhost:4443
GOOGLE_STORAGE_ENABLED=true
# GOOGLE_SERVICE_KEY=

BEE_DEBUG_ENDPOINT=http://localhost:1635
BEE_ENDPOINT=http://localhost:1633


Expand Down
1 change: 0 additions & 1 deletion apps/docs/src/app/docs/environment/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ At the moment Postgres is the default storage and Blobscan won't be able to run
| ----------------------- | -------------------- | -------- | ------------- |
| `SWARM_STORAGE_ENABLED` | Store blobs in Swarm | No | `false` |
| `BEE_ENDPOINT` | Bee endpoint | No | (empty) |
| `BEE_DEBUG_ENDPOINT` | Bee debug endpoint | No | (empty) |

## Blob propagator

Expand Down
2 changes: 1 addition & 1 deletion apps/web/banner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function printBanner() {

if (process.env.SWARM_STORAGE_ENABLED) {
console.log(
`Swarm configuration: beeEndpoint=${process.env.BEE_ENDPOINT}, debugEndpoint=${process.env.BEE_DEBUG_ENDPOINT}`
`Swarm configuration: beeEndpoint=${process.env.BEE_ENDPOINT}`
);
}

Expand Down
2 changes: 1 addition & 1 deletion clis/stats-aggregation-cli/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ main()

return process.exit(1);
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
.finally(gracefulShutdown);
17 changes: 0 additions & 17 deletions packages/blob-storage-manager/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ vi.mock("@ethersphere/bee-js", async () => {
}),
};
}),
BeeDebug: vi.fn().mockImplementation((endpoint) => {
return {
url: endpoint,
getHealth: vi.fn().mockImplementation(() => {
return Promise.resolve({
status: "ok",
});
}),
getAllPostageBatch: vi.fn().mockImplementation(() => {
return [
{
batchID: "mock-batch-id",
},
];
}),
};
}),
};
});

Expand Down
3 changes: 1 addition & 2 deletions packages/blob-storage-manager/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function parseEnv() {
return createEnv({
envOptions: {
server: {
BEE_DEBUG_ENDPOINT: z.string().url().optional(),
BEE_ENDPOINT: requiredStorageConfigSchema("SWARM", z.string().url()),
CHAIN_ID: z.coerce.number().positive().default(1),
FILE_SYSTEM_STORAGE_ENABLED: booleanSchema.default("false"),
Expand Down Expand Up @@ -61,7 +60,7 @@ export function parseEnv() {

if (env.SWARM_STORAGE_ENABLED) {
console.log(
`Swarm configuration: beeEndpoint=${env.BEE_ENDPOINT}, debugEndpoint=${env.BEE_DEBUG_ENDPOINT}`
`Swarm configuration: beeEndpoint=${env.BEE_ENDPOINT}`
);
}

Expand Down
38 changes: 7 additions & 31 deletions packages/blob-storage-manager/src/storages/SwarmStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bee, BeeDebug } from "@ethersphere/bee-js";
import { Bee } from "@ethersphere/bee-js";

import type { BlobscanPrismaClient } from "@blobscan/db";

Expand All @@ -10,14 +10,8 @@ import { BLOB_STORAGE_NAMES } from "../utils";
export interface SwarmStorageConfig extends BlobStorageConfig {
batchId: string;
beeEndpoint: string;
beeDebugEndpoint?: string;
}

export type SwarmClient = {
bee: Bee;
beeDebug?: BeeDebug;
};

async function getBatchId(prisma: BlobscanPrismaClient) {
try {
const state = await prisma.blobStoragesState.findUnique({
Expand All @@ -42,23 +36,19 @@ async function getBatchId(prisma: BlobscanPrismaClient) {
}

export class SwarmStorage extends BlobStorage {
_swarmClient: SwarmClient;
_beeClient: Bee;
batchId: string;

protected constructor({
batchId,
beeDebugEndpoint,
beeEndpoint,
chainId,
}: SwarmStorageConfig) {
super(BLOB_STORAGE_NAMES.SWARM, chainId);

this.batchId = batchId;
try {
this._swarmClient = {
bee: new Bee(beeEndpoint),
beeDebug: beeDebugEndpoint ? new BeeDebug(beeDebugEndpoint) : undefined,
};
this._beeClient = new Bee(beeEndpoint);
} catch (err) {
throw new Error("Failed to create swarm clients", {
cause: err,
Expand All @@ -67,35 +57,21 @@ export class SwarmStorage extends BlobStorage {
}

protected async _healthCheck() {
const healthCheckOps = [];

healthCheckOps.push(this._swarmClient.bee.checkConnection());

if (this._swarmClient.beeDebug) {
healthCheckOps.push(
this._swarmClient.beeDebug.getHealth().then((health) => {
if (health.status !== "ok") {
throw new Error(`Bee debug is not healthy: ${health.status}`);
}
})
);
}

await Promise.all(healthCheckOps);
await this._beeClient.checkConnection();
}

protected async _getBlob(uri: string) {
const file = await this._swarmClient.bee.downloadFile(uri);
const file = await this._beeClient.downloadFile(uri);

return file.data.text();
}

protected async _removeBlob(uri: string): Promise<void> {
await this._swarmClient.bee.unpin(uri);
await this._beeClient.unpin(uri);
}

protected async _storeBlob(versionedHash: string, data: string) {
const response = await this._swarmClient.bee.uploadFile(
const response = await this._beeClient.uploadFile(
this.batchId,
data,
this.getBlobFilePath(versionedHash),
Expand Down
1 change: 0 additions & 1 deletion packages/blob-storage-manager/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export async function createStorageFromEnv(
const swarmStorage = await SwarmStorage.create({
chainId,
beeEndpoint: env.BEE_ENDPOINT,
beeDebugEndpoint: env.BEE_DEBUG_ENDPOINT,
prisma,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe("BlobStorageManager", () => {
swarmStorage = await SwarmStorage.create({
chainId: env.CHAIN_ID,
beeEndpoint: BEE_ENDPOINT,
beeDebugEndpoint: env.BEE_DEBUG_ENDPOINT,
prisma,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("FileSystemStorage", () => {
chainId: env.CHAIN_ID,
});

expect(storage_, "Storage should exists").toBeDefined();
expect(storage_, "Storage should exist").toBeDefined();
expect(storage_.chainId, "Chain ID mistmatch").toEqual(env.CHAIN_ID);
expect(storage_.blobDirPath, "Blob directory path mismatch").toEqual(
env.FILE_SYSTEM_STORAGE_PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("GoogleStorage", () => {
});

it("should create a storage", async () => {
expect(storage, "Storage should exists").toBeDefined();
expect(storage, "Storage should exist").toBeDefined();
expect(storage.chainId, "Chain ID mismatch").toEqual(env.CHAIN_ID);
expect(storage.bucketName, "Bucket name mismatch").toEqual(
env.GOOGLE_STORAGE_BUCKET_NAME
Expand Down
51 changes: 7 additions & 44 deletions packages/blob-storage-manager/test/storages/SwarmStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class SwarmStorageMock extends SwarmStorage {
super(config);
}

get swarmClient() {
return this._swarmClient;
get beeClient() {
return this._beeClient;
}

healthCheck() {
Expand All @@ -25,14 +25,12 @@ class SwarmStorageMock extends SwarmStorage {
describe("SwarmStorage", () => {
let storage: SwarmStorageMock;
const beeEndpoint = "bee-endpoint";
const beeDebugEndpoint = "bee-debug-endpoint";

beforeEach(async () => {
storage = new SwarmStorageMock({
chainId: env.CHAIN_ID,
batchId: "mock-batch-id",
beeEndpoint: beeEndpoint,
beeDebugEndpoint: beeDebugEndpoint,
});
});

Expand All @@ -41,38 +39,19 @@ describe("SwarmStorage", () => {
chainId: env.CHAIN_ID,
beeEndpoint: beeEndpoint,
prisma,
beeDebugEndpoint: beeDebugEndpoint,
});

expect(storage_, "Storage should exists").toBeDefined();
expect(storage_, "Storage should exist").toBeDefined();
expect(storage_.chainId, "Chain ID mismatch").toBe(env.CHAIN_ID);
expect(storage_._swarmClient.bee, "Bee client should exists").toBeDefined();
expect(storage_._swarmClient.bee.url, "Bee client endpoint mismatch").toBe(
expect(storage_._beeClient, "Bee client should exist").toBeDefined();
expect(storage_._beeClient.url, "Bee client endpoint mismatch").toBe(
beeEndpoint
);
expect(
storage_._swarmClient.beeDebug,
"Bee client should exists"
).toBeDefined();
expect(
storage_._swarmClient.beeDebug?.url,
"Bee debug client endpoint mismatch"
).toBe(beeDebugEndpoint);
expect(storage_.batchId, "Batch ID mismatch").toBe(
fixtures.blobStoragesState[0]?.swarmDataId
);
});

it("should not create the beeDebug client when beeDebugEndpoint is not provided", async () => {
const storage_ = await SwarmStorage.create({
chainId: env.CHAIN_ID,
beeEndpoint: beeEndpoint,
prisma,
});

expect(storage_._swarmClient.beeDebug).toBeUndefined();
});

it("should return undefined when trying to get an uri given a blob hash", () => {
const uri = storage.getBlobUri("blob-hash");

Expand All @@ -87,7 +66,7 @@ describe("SwarmStorage", () => {
"should throw a valid error if bee client is not healthy",
async () => {
vi.spyOn(
storage.swarmClient.bee,
storage.beeClient,
"checkConnection"
).mockRejectedValueOnce(new Error("Bee is not healthy: not ok"));

Expand All @@ -99,24 +78,8 @@ describe("SwarmStorage", () => {
}
);

testValidError(
"should throw valid error if bee debug client is not healthy",
async () => {
vi.spyOn(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
storage.swarmClient.beeDebug!,
"getHealth"
).mockRejectedValueOnce(new Error("Bee debug is not healthy: not ok"));
await storage.healthCheck();
},
Error,
{
checkCause: true,
}
);

it("should get a blob given its reference", async () => {
await storage._swarmClient.bee.uploadFile("mock-batch-id", NEW_BLOB_DATA);
await storage._beeClient.uploadFile("mock-batch-id", NEW_BLOB_DATA);

const blob = await storage.getBlob(SWARM_REFERENCE);

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/deploy_vercel_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ environment="production"
variables="CHAIN_ID NEXT_PUBLIC_EXPLORER_BASE_URL NEXT_PUBLIC_NETWORK_NAME NEXT_PUBLIC_SUPPORTED_NETWORKS POSTGRES_STORAGE_ENABLED SWARM_STORAGE_ENABLED GOOGLE_STORAGE_ENABLED DATABASE_URL SECRET_KEY"

# other not so recently updated variables
# o_vars="METRICS_ENABLED BEE_ENDPOINT BEE_DEBUG_ENDPOINT GOOGLE_SERVICE_KEY GOOGLE_STORAGE_BUCKET_NAME GOOGLE_STORAGE_PROJECT_ID"
# o_vars="METRICS_ENABLED BEE_ENDPOINT GOOGLE_SERVICE_KEY GOOGLE_STORAGE_BUCKET_NAME GOOGLE_STORAGE_PROJECT_ID"

add_variable() {
vercel env add $1 $environment
Expand Down
Loading

0 comments on commit 28da372

Please sign in to comment.