MagicBlockは、Ephemeral Rollupというフルオンチェーンを実現する仕組みを提供している。
サンプルをそのまま動かすとエラーになるため(MagicBlockのソースが原因ではなくAnchor利用時の手順の問題で)、以下にその手順を記載する。
前提
以下のドキュメントやソースコードをもとに実行。
手順
- サンプルのダウンロード
% git clone https://github.com/magicblock-labs/magicblock-engine-examples.git
% cd magicblock-engine-examples/anchor-counter
- Yarnパッケージのインストール
% yarn
- anchor_counter-keypairとtoken_minter-keypairのKepairを削除
rm -rf target/deploy/*keypair*
- ProgramsのBuild & Deplory
% anchor build
% anchor deploy
Deploying cluster: https://api.devnet.solana.com
Upgrade authority: /Users/256hax/.config/solana/id.json
Deploying program "token_minter"...
Program path: /Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/target/deploy/token_minter.so...
Program Id: EAharsbLZJUqW2uAL5nsmnVvufTCRpp2ysMs2myQ5wiQ
Signature: 2kbbp32SDCmqVZYqPfSUZAZGTdP6vvHdxonYmYiu9rheaTwjSMaXWqknqyTsj4hfLQfKa1SjGkZibo6XtCi2587T
Deploying program "anchor_counter"...
Program path: /Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/target/deploy/anchor_counter.so...
Program Id: HWw4L4y47mWmRajHRaKWhfcXxCprzMK47R75PDr7p4DT
Signature: 27MnBNMHnk12inc9DuVfpk11jX159MVMur5MSGpy2XVon1KVfhrB5uvx837DnyF6kgcXxi8RY1H4xRESh5e3AQcw
Deploy success
これで、自分がデプロイしたtoken_minterとanchor_counterのProgramsのProgram Idが取得できていることがわかる。
(補足)
もし、ここでSOLが足りないと言われたら、以下からSOLをゲットする。
GitHub認証すると10SOLまで申請できる。
デプロイには2〜3SOLかかるので(デプロイ時にかかるが、そのあと概ねのSOLが戻って来る)、多めに用意する。
- Program Idを書き換える
Anchor.toml
[programs.devnet]
# anchor_counter = "852a53jomx7dGmkpbFPGXNJymRxywo3WsH1vusNASJRr"
# ↓ anchor_counterのProgram Id
anchor_counter = "HWw4L4y47mWmRajHRaKWhfcXxCprzMK47R75PDr7p4DT"
# token-minter = "HfPTAU1bZBHPqcpEGweinAH9zsPafYnnaxk4k5xsTU3M"
# ↓ token_minterのProgram Id
token-minter = "EAharsbLZJUqW2uAL5nsmnVvufTCRpp2ysMs2myQ5wiQ"
programs/anchor-counter/src/lib.rs
# declare_id!("852a53jomx7dGmkpbFPGXNJymRxywo3WsH1vusNASJRr");
declare_id!("HWw4L4y47mWmRajHRaKWhfcXxCprzMK47R75PDr7p4DT");
programs/anchor-minter/src/lib.rs
# declare_id!("HfPTAU1bZBHPqcpEGweinAH9zsPafYnnaxk4k5xsTU3M");
declare_id!("EAharsbLZJUqW2uAL5nsmnVvufTCRpp2ysMs2myQ5wiQ");
- テストする
% anchor test
よくあるエラー
いずれもサンプルをそのままダウンロードして実行すると、Program Idがマッチしないためエラーが出る。MagicBlockがデプロイしたProgramを自身が使おうとしてして、Authorityがないことが原因。
まず自分でProgramsをデプロイして、そのProgram Idを書き換える必要がある。
% anchor test --skip-deploy --skip-build
Found a 'test' script in the Anchor.toml. Running it as a test suite!
Running test suite: "/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/Anchor.toml"
yarn run v1.22.19
$ /Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'
Error: target/idl/anchor_counter.json doesn't exist. Did you run `anchor build`?
at Object.get (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/@coral-xyz/anchor/src/workspace.ts:65:15)
at Suite.<anonymous> (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/tests/anchor-counter.ts:26:36)
at Object.create (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/interfaces/common.js:148:19)
at context.describe.context.context (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/interfaces/bdd.js:42:27)
at Object.<anonymous> (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/tests/anchor-counter.ts:11:1)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
at Module.m._compile (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/ts-node/src/index.ts:439:23)
at node:internal/modules/cjs/loader:1698:10
at Object.require.extensions.<computed> [as .ts] (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/ts-node/src/index.ts:442:12)
at Module.load (node:internal/modules/cjs/loader:1303:32)
at Function._load (node:internal/modules/cjs/loader:1117:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
at Module.require (node:internal/modules/cjs/loader:1325:12)
at require (node:internal/modules/helpers:136:16)
at Object.exports.requireOrImport (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/nodejs/esm-utils.js:60:20)
at Object.exports.loadFilesAsync (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
at singleRun (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: No such file or directory (os error 2)
% anchor test
Error: Function _ZN14spl_token_20229extension21confidential_transfer12verify_proof30verify_transfer_with_fee_proof17h87f825876ef609b7E Stack offset of 4392 exceeded max offset of 4096 by 296 bytes, please minimize large stack variables. Estimated function frame size: 4472 bytes. Exceeding the maximum stack offset may cause undefined behavior during execution.
Error: A function call in method _ZN14spl_token_20229extension21confidential_transfer12verify_proof30verify_transfer_with_fee_proof17h87f825876ef609b7E overwrites values in the frame. Please, decrease stack usage or remove parameters from the call.The function call may cause undefined behavior during execution.
Error: A function call in method _ZN14spl_token_20229extension21confidential_transfer12verify_proof30verify_transfer_with_fee_proof17h87f825876ef609b7E overwrites values in the frame. Please, decrease stack usage or remove parameters from the call.The function call may cause undefined behavior during execution.
Error: A function call in method _ZN14spl_token_20229extension21confidential_transfer12verify_proof30verify_transfer_with_fee_proof17h87f825876ef609b7E overwrites values in the frame. Please, decrease stack usage or remove parameters from the call.The function call may cause undefined behavior during execution.
Error: A function call in method _ZN14spl_token_20229extension21confidential_transfer12verify_proof30verify_transfer_with_fee_proof17h87f825876ef609b7E overwrites values in the frame. Please, decrease stack usage or remove parameters from the call.The function call may cause undefined behavior during execution.
Compiling anchor-counter v0.1.0 (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/programs/anchor-counter)
Compiling token-minter v0.1.0 (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/programs/token-minter)
Finished `release` profile [optimized] target(s) in 1.62s
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.21s
Running unittests src/lib.rs (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/target/debug/deps/token_minter-bd03a0255a1e1996)
Compiling anchor-counter v0.1.0 (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/programs/anchor-counter)
Finished `release` profile [optimized] target(s) in 0.81s
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.17s
Running unittests src/lib.rs (/Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/target/debug/deps/anchor_counter-c3d59c895c331b51)
Deploying cluster: https://api.devnet.solana.com
Upgrade authority: /Users/256hax/.config/solana/id.json
Deploying program "token_minter"...
Program path: /Users/256hax/Desktop/tmp/magicblock-engine-examples/anchor-counter/target/deploy/token_minter.so...
Error: Program's authority Some(Ec6jL2GVTzjfHz8RFP3mVyki9JRNmMu8E7YdNh45xNdk) does not match authority provided HXtBm8XZbxaTt41uqaKhwUAa6Z1aPyvJdsZVENiWsetg
There was a problem deploying: Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "" }.