로컬 hardhat 노드에서 FleetRegistry 프록시를 업그레이드했어요. V1에는 디바이스가 37개 등록돼 있었어요. scripts/upgrade.js로 V2 구현체를 배포하고 프록시에서 upgradeToAndCall(implAddr, "0x")를 호출했어요.
업그레이드 후에는 이래요:
- 프록시의
deviceCount()가 0을 반환해요
devices(id)는 예전 항목을 그대로 반환해서 매핑은 살아 있어요
registrationFee()는 37을 반환하는데, 수수료를 설정한 사람이 아무도 없어서 registerDevice가 이제 37 wei를 요구해요
처음에는 데이터가 빈 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.