帖子
分享您的知识。
+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
答案
1让我解释一下解决方案以及如何解决您在发布或升级模块时在 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.
你知道答案吗?
请登录并分享。
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.