feat: expose a stable TRE instance identifier#33
Open
nahimterrazas wants to merge 1 commit into
Open
Conversation
Add hre.tre.instanceId(): a stable identifier for the specific TRE node the active network points at. When the plugin launched the TRE container, the id is derived from the container's own identity (docker container id + StartedAt), hashed. Both change on a fresh `docker run` and StartedAt also changes on `docker start`, so the id distinguishes one boot from the next even when the chain is byte-for-byte deterministic. This replaces deriving the id from the genesis block hash, which a TRE booted from identical config reproduces on every restart and so cannot tell two restarts apart. The genesis hash is kept only as a fallback for an externally-provided TRE (one the plugin did not launch); its limitation for deterministic external restarts is documented on the API. Also answer `hardhat_metadata` on tron-typed networks via an extendProvider hook, mirroring the built-in Hardhat Network. Upgrades tooling probes this RPC to key its per-instance deployment manifests; exposing the instance id at the shared network provider lets that tooling isolate a restarted local chain's records natively, through its own internal manifest lookups, instead of reusing a stale manifest keyed by chain id alone. Tested: a docker-gated suite boots two fresh TRE instances sequentially and asserts their ids differ while their genesis blocks match; the e2e suite checks the provider answers hardhat_metadata with a chainId matching eth_chainId and the same instance id.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
hre.tre.instanceId(): a stable identifier for the specific TRE node the active network points at, and exposes it to upgrades tooling by answeringhardhat_metadataon tron-typed networks.What
instanceId()returnsA string that identifies one running TRE instance. It is resolved once and cached per
(network, url).hardhat test/node/compile, or akeepRunningrestart), the id is0x+sha256(<docker container id> + "|" + <State.StartedAt>). The container id changes on every freshdocker runandStartedAtchanges on everydocker start, so the id is distinct for each boot even when the chain is otherwise byte-for-byte deterministic.docker-compose up, or a parallel-test runner pointing at its ownTRE_URL), the container identity is unknown, so the id falls back to the genesis block hash. Because a TRE booted from identical config reproduces the same genesis block, two deterministic restarts of an external TRE will share an id. This limitation is documented on the API type; let the plugin manage the container lifecycle if you need a guaranteed-fresh id per restart.This replaces deriving the id from the genesis hash alone, which could not tell two deterministic restarts of the same chain apart.
Provider metadata exposure
An
extendProviderhook makes tron-typed networks answer thehardhat_metadataJSON-RPC method, mirroring the built-in Hardhat Network. The response reports the chain id (read frometh_chainId, so it always matches) and the instance id above. Tooling such as@openzeppelin/upgrades-coreprobes this method to key its per-instance deployment manifests; exposing the id at the shared network provider lets that tooling isolate a restarted local chain's records through its own internal manifest resolution, instead of reusing a manifest keyed by chain id alone. Only tron-typed networks are wrapped; every other network's provider is returned untouched, and no other RPC behavior changes.Test coverage
hardhat_metadatawith achainIdmatchingeth_chainIdand aninstanceIdequal tohre.tre.instanceId(), and that the external-TRE path falls back to the genesis-derived id.Both are gated the same way as the existing e2e tests, so CI without a container runtime stays green.