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

Kranthi/remove subsidize #34

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/early-carrots-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocol.land/sync': minor
---

remove repo subsidization
30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Protocol Land Sync package simplifies the process of syncing Git repositorie

To sync a repository with Protocol Land, you can either run it manually from your local Git repository's root folder or set up a GitHub Action if your repository is hosted on GitHub.

For both methods, **you need an Arweave wallet with some $AR** to pay for the upload, unless your repository uses less than 100KB of data.
For both methods, **you need an Arweave wallet with some $AR** to pay for the upload.

### GitHub Actions

Expand Down Expand Up @@ -60,24 +60,9 @@ jobs:
REPO_TITLE: ${{ github.event.repository.name }}
REPO_DESCRIPTION: ${{ github.event.repository.description }}
WALLET: ${{ secrets.WALLET }}
# Optional Environment variables for ArSeeding strategy
STRATEGY: "ARSEEDING"
ARSEEDING_TOKEN_SYMBOL: "AR"
# Use personal funds in case of transaction subsidization failure
HANDLE_SUBSIDY_ERROR: "true"

```


> [!NOTE]
> Currently all Sync transactions are subsidized by Protocol Land. In case of subsidizing service failure, Sync program will exit unless `HANDLE_SUBSIDY_ERROR` env is set which lets you pay for the transaction from your wallet and continue.


> [!NOTE]
> Only include `STRATEGY` and `ARSEEDING_TOKEN_SYMBOL` environment variables for using [ArSeeding](https://web3infra.dev/docs/arseeding/introduction/lightNode/) to sync your repositories to Protocol Land.
> Supported Arweave tokens for ArSeeding strategy are: `['XYZ', 'ARDRIVE', 'PIA', 'VRT', 'U', 'STAMP', 'AR']`.
> You need [EverPay](https://app.everpay.io/) balances for these tokens to use ArSeeding strategy.

> [!NOTE]
> This GitHub Action **will run on every push to the 'main' branch**.
> If you want to run it manually, comment the lines after `on:` and uncomment the `workflow_dispatch:` line.
Expand Down Expand Up @@ -107,25 +92,12 @@ Follow `1.` and `2.` from the previous section to set up a GitHub Secret.
WALLET='YOUR_WALLET_JWK_HERE'
REPO_TITLE='Your Repo Name Here'
REPO_DESCRIPTION='Your Repo Description Here'

# Optional Environment variables for ArSeeding strategy

STRATEGY='ARSEEDING'
ARSEEDING_TOKEN_SYMBOL='AR'

# Use personal funds in case of transaction subsidization failure

HANDLE_SUBSIDY_ERROR='true'
```

Replace `'YOUR_WALLET_JWK_HERE'` with your Arweave wallet's JWK (JSON Web Key).

Currently Sync transaction costs are subsidized by Protocol Land and in case of subsidization failure, Sync program will exit unless `HANDLE_SUBSIDY_ERROR` env is set which lets you pay for the transaction from your wallet and continue.
If the compressed size of your repository exceeds 100kb, ensure your wallet has enough $AR to cover the transaction fees.

These environment variables (`WALLET`, `REPO_TITLE`, and `REPO_DESCRIPTION`) are crucial for setting up your repository and providing a meaningful description.

`STRATEGY` and `ARSEEDING_TOKEN_SYMBOL` are needed for using [ArSeeding](https://web3infra.dev/docs/arseeding/introduction/lightNode/) to sync repositories to Protocol Land. Supported Arweave tokens for ArSeeding strategy are: `['XYZ', 'ARDRIVE', 'PIA', 'VRT', 'U', 'STAMP', 'AR']`.

4. **(optional)** Checkout locally all the branches you want synced. The tool uploads all the branches you have checked out locally with Git.
Run this bash command to checkout all the remote branches:
Expand Down
84 changes: 3 additions & 81 deletions src/lib/arweaveHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,9 @@ export function getActivePublicKey() {
}

export async function uploadRepo(zipBuffer: Buffer, tags: Tag[]) {
//Subsidized Upload
try {
const uploadedTx = await subsidizedUpload(zipBuffer, tags);
const serviceUsed = uploadedTx.bundled ? 'Turbo' : 'Arweave';

console.log(
`[ PL SUBSIDIZE ] Posted Tx to ${serviceUsed}: ${uploadedTx.data.repoTxId}`
);

return uploadedTx.data.repoTxId;
} catch (error) {
const userWantsToPay = process.env.HANDLE_SUBSIDY_ERROR === 'true';

if (!userWantsToPay) {
throw '[ PL SUBSIDIZE ] Failed to subsidize this transaction.';
}
//continue
}

const isArSeedingStrategy = process.env.STRATEGY === 'ARSEEDING';
if (isArSeedingStrategy) {
const arweaveTxId = await arseedingUpload(zipBuffer, tags);
console.log('Posted Tx to Arseeding: ', arweaveTxId);
return arweaveTxId;
} else {
try {
// upload compressed repo using turbo
const turboTxId = await turboUpload(zipBuffer, tags);
console.log('Posted Tx to Turbo: ', turboTxId);
return turboTxId;
} catch (error) {
console.log('Error uploading using turbo, trying with Arweave...');
// let Arweave throw if it encounters errors
const arweaveTxId = await arweaveUpload(zipBuffer, tags);
console.log('Posted Tx to Arweave: ', arweaveTxId);
return arweaveTxId;
}
}
const arweaveTxId = await arweaveUpload(zipBuffer, tags);
console.log('Posted Tx to Arweave: ', arweaveTxId);
return arweaveTxId;
}

async function arweaveUpload(zipBuffer: Buffer, tags: Tag[]) {
Expand Down Expand Up @@ -116,46 +81,3 @@ export async function turboUpload(zipBuffer: Buffer, tags: Tag[]) {

return dataItem.id;
}

export async function subsidizedUpload(zipBuffer: Buffer, tags: Tag[]) {
if (!jwk) throw '[ turbo ] No jwk wallet supplied';

const node = 'https://subsidize.saikranthi.dev/api/v1/postrepobuffer';
const uint8ArrayZip = new Uint8Array(zipBuffer);
const signer = new ArweaveSigner(jwk);
const address = await getAddress();

const dataItem = createData(uint8ArrayZip, signer, { tags });
await dataItem.sign(signer);

const bundle = await bundleAndSignData([dataItem], signer);
const bundleBuffer = bundle.getRaw();

const formData = new FormData();
formData.append('txBundle', new Blob([bundleBuffer]));
formData.append('platform', 'CLI');
formData.append('owner', address);

const res = await fetch(`${node}`, {
method: 'POST',
headers: {
Accept: 'application/json',
},
body: formData,
});
const upload = (await res.json()) as SubsidizedUploadJsonResponse;

if (!upload || !upload.success)
throw new Error(
`[ turbo ] Posting repo with turbo failed. Error: ${res.status} - ${res.statusText}`
);

return upload;
}

export type SubsidizedUploadJsonResponse = {
success: boolean;
bundled: boolean;
data: { repoTxId: string };
error?: string;
};
Loading