帖子
分享您的知识。
+10
Sui Move 模块出版物中的 “多源验证错误” ——自动错误解决
使用 Sui Move 的开发人员在尝试发布或升级模块时经常遇到与 “发现多源验证错误” 相关的问题. 这些错误是由于本地依赖项与其链上依赖项之间的不匹配而发生的,从而导致发布失败和部署挑战. 以下是开发人员面临的错误的综合示例:
Failed to publish the Move module(s), reason: [warning] Multiple source verification errors found:
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::vec_set
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::vec_map
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000001::MoveStdlib::bit_vector
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000001::MoveStdlib::ascii
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::hex
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::zklogin_verified_id
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::prover
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::coin
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::dynamic_field
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::transfer
- On-chain version of dependency Sui::zklogin_verified_id was not found.
- On-chain version of dependency Sui::zklogin_verified_issuer was not found.
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::tx_context
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::transfer_policy
- Local dependency did not match its on-chain version at 0000000000000000000000000000000000000000000000000000000000000002::Sui::kiosk
这个问题通常是由于:
- 本地开发环境(例如 Sui CLI)和链上状态之间的版本不匹配.
- 网络间软件包配置的差异(例如,主网与测试网). 3.链上环境中缺少或过时的依赖关系.
关键问题 -在发布过程中,我们如何自动检测和解决这些依赖关系不匹配的问题? -可以开发哪些工具或脚本来确保本地依赖关系始终与链上依赖项保持一致? -有没有办法通过将依赖关系检查集成到现有的 CI/CD 管道或增强 Sui SDK 来简化这个过程?
你的任务是提出一个解决这些挑战的解决方案,确保Sui Move开发人员的部署更加顺畅和可靠. 请务必在下面发布您的解决方案.
- Sui
- SDKs and Developer Tools
答案
5让我解释一下解决方案以及如何解决您在发布或升级模块时在 Sui Move 中遇到的 “多源验证错误**”. 当你在本地开发 Sui Move 模块时,你需要在 Move.toml 文件中指定依赖关系,如下所示:
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui", subdir = "crates/sui-framework", rev = "some-revision" }
rev 字段表示您正在使用的 Sui 框架的特定版本(分支、标签或提交哈希).
如果此版本与在区块链上为目标网络部署的版本不匹配,则在发布或升级期间会出现验证错误. 例如,区块链可能使用Sui::vec_set
比您的本地代码更旧的版本,或者类似的模块Sui::zklogin_verified_id
可能未在您的目标网络上发布.
我的解决方案是一个Bash脚本,该脚本根据您的目标网络使用正确的Sui框架版本更新您的Move.toml文件,然后通过构建软件包来验证设置. 将其另存为update-deps.sh
您的项目目录(Move.toml 所在的位置).
#!/bin/bash
# Function to get the latest commit hash for the network-specific branch
get_latest_rev() {
network=$1
case $network in
"testnet")
branch="framework/testnet"
;;
"devnet")
branch="framework/devnet"
;;
"mainnet")
branch="main"
;;
*)
echo "Invalid network specified. Use 'testnet', 'devnet', or 'mainnet'."
exit 1
;;
esac
# Fetch the latest commit hash from the specified branch
rev=$(git ls-remote https://github.com/MystenLabs/sui $branch | cut -f1)
if [ -z "$rev" ]; then
echo "Failed to fetch revision for branch $branch."
exit 1
fi
echo $rev
}
# Function to update Move.toml with the correct revision
update_move_toml() {
network=$1
rev=$(get_latest_rev $network)
# Update the rev field in Move.toml for the Sui dependency
sed -i "s/rev = .*/rev = \"$rev\"/" Move.toml
echo "Updated Move.toml with rev = $rev for $network"
}
# Main function
main() {
if [ $# -ne 1 ]; then
echo "Usage: $0 <network> (e.g., testnet, devnet, mainnet)"
exit 1
fi
network=$1
update_move_toml $network
# Attempt to build the package
if ! sui move build; then
echo "Build failed. Please check for missing dependencies or other issues."
else
echo "Build successful. You can now publish the package."
fi
}
# Run the main function with provided arguments
main "$@"
你可以 Run chmod +x update-deps.sh
用你的目标网络运行和执行它. 比如 ./update-deps.sh testnet
所以这是你终端的输出结果:
harryphan@MacBook-Pro-2 hello % ./update-deps.sh testnet
Updated Move.toml with rev = 556b6e14896a09f95e7cf460bc8220a3bf997979 for testnet
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING hello
Build successful. You can now publish the package.
我的答案(获得 +10 赏金):
为了自动避免 Sui Move 模块部署中的 “多源验证错误”,我建议使用以下自动解析工作流程:
🛠️ 分步解决方案:
- 与链上版本同步
在发布之前,您的Move.toml必须与目标网络(测试网、开发网络或主网)上使用的确切框架版本相匹配.
否则,像 Sui:: vec_set 或 Sui:: transfer_policy 这样的依赖关系不匹配将导致发布失败.
- 使用自动化脚本
创建一个名为 update-deps.sh 的 bash 脚本,该脚本:
✅ 获取网络的正确修订哈希 ✅ 更新你的 move.toml 依赖关系 ✅ 重建您的软件包以检查兼容性
#!/bin/bash
get_latest_rev () { 网络 = 1 美元 案例 $network in “测试网”) branch= “框架/测试网”;; “devnet”) branch= “框架/开发网络”;; “主网”) 分支= “主要”;; *) echo “网络无效!使用:测试网/开发网络/主网”;退出 1; esac
rev=$ (git ls-remote https://github.com/MystenLabs/sui $branch | cut-f1) echo $rev }
update_move_toml () { rev=$ (get_latest_rev $1) sed-i “s/rev =. */rev =\ “$rev\”/” Move.toml echo “✅ 更新了 Move.toml,其中 rev = $rev” }
主 () {
[$#-ne 1] && echo “使用量:$0
主要 “$@”
✅ 用法:
chmod +x update-deps.sh . /update-deps.sh 测试网
这样可以确保您的本地环境使用链上部署的确切Sui和MovestdLib版本.
🚀 额外提示:
CI/CD 集成:在 sui move 发布之前,将此脚本添加到您的 GitHub 操作工作流程中.
错误记录:记录版本不匹配以帮助更快地检测升级.
模块安全:切勿更改升级中的公共结构字段或顺序——Sui 会拒绝它们.
通过自动依赖同步,您可以消除模块验证失败的 #1 原因,并加快生产部署.
提交者:md rifat hossen 如果你想把这个翻译成孟加拉语还是想要 CI/CD YAML 示例,请告诉我 ✅
让我阐明一种可靠的方法来解决开发人员在尝试发布或升级 Sui Move 模块时经常遇到的 “多源验证错误”.
在 Sui Move 开发过程中,外部依赖关系在 Move.toml 清单中声明,其结构通常如下所示:
[dependencies] Sui = { git = "https://github.com/MystenLabs/sui", subdir = "crates/sui-framework", rev = "some-revision" }
rev 密钥指定了要在本地使用的 sui-framework 存储库的精确提交哈希、分支或标签. 但是,当该本地参考与部署在区块链上的权威版本不一致时,就会出现复杂情况,从而导致部署期间的源代码验证冲突.
例如,您可能会看到错误消息,例如:
Local dependency did not match its on-chain version at 0x2::Sui::coin On-chain version of dependency Sui::zklogin_verified_id was not found.
这些差异是由于本地解析的字节码和链上部署的二进制文件之间的差异而出现的. 它们可以归因于:
-
Move.toml 中的版本不一致或过时
-
开发者环境与目标网络的部署状态(例如,主网、测试网、开发网络)之间的差异
3.在本地使用尚未在链上实例化的模块
为了缓解这个摩擦点,我提出了一个名为 update-deps.sh 的自动化 Bash 实用程序.
这个脚本:
a. 确定与所需网络对应的 Sui 框架的最新规范修订哈希.
b. 使用正确的提交哈希值以编程方式更新 Move.toml 中的 rev 字段.
c. 通过 sui move build 调用本地编译版本来验证环境,抢先出现运行时发布错误.
为此,请将此脚本放到您的 Move 项目的根目录中:
#!/bin/bash
# Retrieve the most recent commit hash from the appropriate branch based on network context
get_latest_rev() {
network=$1
case $network in
"testnet")
branch="framework/testnet"
;;
"devnet")
branch="framework/devnet"
;;
"mainnet")
branch="main"
;;
*)
echo "Invalid network specified. Use 'testnet', 'devnet', or 'mainnet'."
exit 1
;;
esac
rev=$(git ls-remote https://github.com/MystenLabs/sui $branch | cut -f1)
if [ -z "$rev" ]; then
echo "Failed to retrieve commit hash for branch $branch."
exit 1
fi
echo $rev
}
# Apply the revision update to Move.toml
update_move_toml() {
network=$1
rev=$(get_latest_rev $network)
sed -i "s/rev = .*/rev = \"$rev\"/" Move.toml
echo "Move.toml updated with rev = $rev for network: $network"
}
# Entrypoint
main() {
if [ $# -ne 1 ]; then
echo "Usage: $0 <network> (e.g., testnet, devnet, mainnet)"
exit 1
fi
network=$1
update_move_toml $network
# Attempt to compile the package
if ! sui move build; then
echo "Build failed. Please inspect for unresolved dependencies or other conflicts."
else
echo "Build succeeded. You are now primed for module publication."
fi
}
main "$@"
之后,向脚本授予可执行权限,chmod +x update-deps.sh
并通过提供目标部署网络 `./update-deps.sh testnet.
Finally, your expected terminal output should look like this:
`` $ ./update-deps.sh testnet
Move.toml updated with rev = 556b6e14896a09f95e7cf460bc8220a3bf997979 for network: testnet UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git INCLUDING DEPENDENCY Sui INCLUDING DEPENDENCY MoveStdlib BUILDING hello Build succeeded. You are now primed for module publication.
让我在 Sui Move 模块出版物中为自动验证和解决依赖关系提供一个全面的解决方案:
核心概念
该解决方案围绕三个关键组件展开:
- 依赖状态管理
i. 本地依赖关系跟踪
二. 链上状态验证
三. 版本比较逻辑
- 自动分辨率
i. 版本同步
二. 缺少依赖项安装
三. 配置验证
3.集成框架
i. CI/CD 管道挂钩
二. SDK 扩展
三. 错误报告系统
实现细节
以下是处理依赖关系验证和解决的核心实现:
// dependency-verifier.ts
import { SuiClient } from '@mysten/sui.js';
import { execSync } from 'child_process';
interface DependencyState {
address: string;
name: string;
localVersion: string;
onChainVersion: string;
status: 'matched' | 'mismatched' | 'missing';
}
class DependencyVerifier {
private client: SuiClient;
private localDeps: Map<string, string>;
private onChainDeps: Map<string, string>;
constructor(network: string) {
this.client = new SuiClient(network);
this.localDeps = new Map();
this.onChainDeps = new Map();
}
async verifyDependencies(): Promise<DependencyState[]> {
await this.loadLocalDependencies();
await this.loadOnChainDependencies();
const results: DependencyState[] = [];
for (const [address, localVersion] of this.localDeps) {
const onChainVersion = this.onChainDeps.get(address);
results.push({
address,
name: this.getDependencyName(address),
localVersion,
onChainVersion,
status: this.determineStatus(localVersion, onChainVersion)
});
}
return results;
}
private async resolveDependencies(results: DependencyState[]): Promise<void> {
for (const dep of results) {
if (dep.status === 'missing') {
await this.installMissingDependency(dep.address);
} else if (dep.status === 'mismatched') {
await this.syncDependencyVersion(dep.address, dep.onChainVersion);
}
}
}
private determineStatus(local: string, onChain: string): DependencyState['status'] {
if (!onChain) return 'missing';
if (local !== onChain) return 'mismatched';
return 'matched';
}
}
CI/CD 集成
以下是将验证器集成到您的 CI/CD 管道中的方法:
# .github/workflows/dependency-check.yml
name: Dependency Verification
on:
push:
branches:
- main
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Dependencies
run: npm install
- name: Verify Dependencies
run: npm run verify:dependencies
- name: Publish
if: success()
run: sui move publish
SDK 集成
通过依赖关系验证扩展 Sui SDK:
// sui-sdk-extensions.ts
import { SuiClient } from '@mysten/sui.js';
import { DependencyVerifier } from './dependency-verifier';
declare module '@mysten/sui.js' {
interface SuiClient {
verifyDependencies(): Promise<void>;
}
}
SuiClient.prototype.verifyDependencies = async function() {
const verifier = new DependencyVerifier(this.network);
const results = await verifier.verifyDependencies();
if (results.some(r => r.status !== 'matched')) {
console.error('Dependency mismatches found:');
results.forEach(r => {
if (r.status !== 'matched') {
console.error(`- ${r.name}: ${r.status}`);
}
});
throw new Error('Dependency verification failed');
}
};
用法示例
// package.json scripts
{
"scripts": {
"verify:dependencies": "ts-node scripts/verify-dependencies.ts",
"publish": "sui move publish",
"publish:with-verify": "npm run verify:dependencies && npm run publish"
}
}
最佳实践
- 版本管理
i. 对所有依赖项使用语义版本控制
二. 维护版本锁定文件
三. 文档版本要求
- 错误处理
i. 实施详细的错误报告
二. 提供明确的解决步骤
三. 记录依赖关系状态以进行调试
3.开发工作流程
i. 在本地测试之前运行验证
二. 使用 CI 管道进行自动检查
三. 在各个环境中保持一致的依赖关系版本
以下是解释和解决 Sui Move 在发布或升级时出现 “多源验证错误” 的方法:
这些错误通常是因为你的本地Sui框架版本(来自Move.toml)与目标区块链(测试网、开发网络、主网)使用的版本不匹配. 这种不匹配会导致验证失败——尤其是当诸如Sui:: vec_set或Sui:: zklogin_verified_id之类的模块不存在或不同版本的字节码不同时.
要修复此问题,请更新 [依赖关系] 部分中的修订版,使其与针对目标网络在链上部署的版本完全匹配. 与其手动执行此操作,不如使用提供的 Bash 脚本 (update-deps.sh) 来自动执行此过程.
这个脚本: • 从右分支(框架/测试网、框架/开发网络或主分支)提取最新的提交哈希值. • 更新 Move.toml 中的转速值. • 使用 sui move build 生成软件包以确认安装有效.
用法示例:
chmod +x update-deps.sh . /update-deps.sh 测试网
你会得到如下输出:
更新了 Move.toml,测试网版本为 rev = 556b6e14896a09f95e7cf460bc8220a3bf997979 更新 GIT 依赖关系 https://github.com/MystenLabs/sui.git 包括依赖套餐 包括依赖关系 movestdLib 大楼你好 成功构建. 您现在可以发布该软件包了.
这样可以确保您的本地版本与链的运行时相匹配,从而避免源代码验证错误
你知道答案吗?
请登录并分享。
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
