Closed arthurgousset closed 3 months ago
most likely the reason for it is because the config is shared across networks (it's global) and because the addresses differ between networks it will fail, I see few solutions right now:
openingly thinking of the scenarios
you might set the node and gasCurrency in the config and then
--node
just for one commandgasCurrency
just for one commandset:config
set:config
1 and 3 will cause problems. 2 and 4 not so much
for 3. one option is to set gasCurrency to null if none is passed. rather than getting from old config. (and best to show that info to the user if there was one ("a gas token was being used on previous network if youd like to use one on this network please set")
config per network could be compatible with this too al though the config is also what stores the network.
for situation 1. A per network config would make this a none issue. otherwise would have to either fail nicer or revert to celo
having said that my view now is config like
{
node: url
gasCurrency: LEGACY | {
[chainID]: 0xString | CELO
}
}
this is harder than i expected. mostly because i've been trying to keep the tests working but i think that is kinda fruitless. beyond the issue with changing networks i see a few other issues that have me want to change things around
1/ when calling config:set
the current contractkit instance is used (so if you were on 'alfajores' and call config:set -- node 'mainnet' --gasCurrency <string for CUSD on mainnet>
it would have failed)
it converts LegacyConfig. but only when calling writeConfig. if i was to run config:get
only readConfig
is called and so the legacy one would be shown
writeConfig will take a Legacy Config or a new Config. but i now need to merge new configs (per chain id). and since readConfig might return a Legacy i would need to do a lot of logic outside of the function around merging gasCurrency: {[chainIdAlfajores]: "0x",...previous}
what im getting at is doing conversions inside write feels like its making things extra complicated
getGasCurrency will secretly do a write if it finds an old config. if reads are happening on writes at all i think it should be in readConfig.so it always happens
instead i think i will move the conversion to the readConfig.
there is already precident for it with the nodeUrl to node conversion
Thanks for working on this @aaronmgdr! One idea (out-of-scope for this PR), we could consider removing the option to set a default --node
and --gasCurrency
in config:<...>
. I'm not sure setting a default node and fee currency is particularly useful. Particularly, considering the implementation is relatively complex.
Effectively, all commands would require the --node
and --gasCurrency
global flags to be set explicitly in every command. That would simplify the celocli
code base and provide more deterministic behaviour for users (e.g. avoid conflicts with configs that were set in the past, but forgotten).
What do you think about that @aaronmgdr ?
I think i actually have something that works well now.
only thing is there are tests for writing the config like
test('gasCurrency StableToken (legacy)', async () => {
await writeConfig(PATH, { gasCurrency: 'cUSD' }, kit)
im not sure why we added tests for that as i thought we decided not to support that anymore
Thanks for working on this @aaronmgdr! One idea (out-of-scope for this PR), we could consider removing the option to set a default
--node
and--gasCurrency
inconfig:<...>
. I'm not sure setting a default node and fee currency is particularly useful. Particularly, considering the implementation is relatively complex.Effectively, all commands would require the
--node
and--gasCurrency
global flags to be set explicitly in every command. That would simplify thecelocli
code base and provide more deterministic behaviour for users (e.g. avoid conflicts with configs that were set in the past, but forgotten).What do you think about that @aaronmgdr ?
i dont like so much. i actually find it hard to undersand that you don't think setting a default is useful.
I think its more or less solved now and we should only be considering solutions that are IN scope.
we fixed this by removing gasCurrency from config.
Package
@celo/celocli
Have you ensured that all of these are up to date?
What version of the package are you on?
@celo/celocli/5.0.0-beta.0 darwin-arm64 node-v18.17.1
What command or function is the bug in?
celocli network:whitelist
Operating System
macOS (Apple Silicon)
Describe the bug
Running the command with the node set to Alfajores throws an error:
The same command works on Mainnet: