我在本地 hardhat 节点上升级了我的 FleetRegistry 代理。V1 里注册了 37 台设备。我用 scripts/upgrade.js 部署了 V2 的实现,然后在代理上调用了 upgradeToAndCall(implAddr, "0x")。
升级后:
- 在代理上调用
deviceCount() 返回 0
devices(id) 仍然能返回旧的条目,所以 mapping 没丢
registrationFee() 返回 37,但从来没人设置过费用,所以 registerDevice 现在要收 37 wei
一开始我以为是空 data 的 upgradeToAndCall 把代理里的什么东西重置了。后来我又觉得 .openzeppelin/ 里的 manifest 过期了,就把它删了。没有任何变化。
我不明白为什么一个计数器变成了 0,而其他数据都正常。
V1 的状态变量:
mapping(bytes32 => Device) public devices;
uint32 public minFwVersion;
uint256 public deviceCount;
V2:
mapping(bytes32 => Device) public devices;
uint32 public minFwVersion;
uint256 public registrationFee; // new in V2, kept next to the other config
uint256 public deviceCount;
升级脚本没有调用 upgrades.validateUpgrade。我在那里写了条注释,说 UUPS 已经通过 proxiableUUID 拒绝有问题的实现了。
函数除了费用检查之外都一样。Solidity 0.8.24,OpenZeppelin upgradeable contracts,装了 hardhat-upgrades 插件。
问题是出在我的 V2 合约里,还是出在我升级的方式上?我现在没法运行这个项目,所以只能描述我当时看到的情况。
从英语翻译·查看原文I upgraded my FleetRegistry proxy on a local hardhat node. V1 had 37 devices registered. I deployed the V2 implementation with scripts/upgrade.js and called upgradeToAndCall(implAddr, "0x") on the proxy.
After the upgrade:
deviceCount() on the proxy returns 0
devices(id) still returns the old entries, so the mapping survived
registrationFee() returns 37, but nobody ever set a fee, so registerDevice now wants 37 wei
First I thought the empty-data upgradeToAndCall reset something in the proxy. Then I thought the manifest in .openzeppelin/ was stale, so I deleted it. Nothing changed.
I don't understand why one counter went to zero while the other data is fine.
State variables, V1:
mapping(bytes32 => Device) public devices;
uint32 public minFwVersion;
uint256 public deviceCount;
V2:
mapping(bytes32 => Device) public devices;
uint32 public minFwVersion;
uint256 public registrationFee; // new in V2, kept next to the other config
uint256 public deviceCount;
The upgrade script does not call upgrades.validateUpgrade. My comment there says UUPS already rejects a bad implementation via proxiableUUID.
Functions are the same except for the fee check. Solidity 0.8.24, OpenZeppelin upgradeable contracts, hardhat-upgrades plugin installed.
Is the problem in my V2 contract or in how I upgrade? I can't run the project right now, so I only describe what I saw.