aionnetwork / aion-docs

Documentation for the Aion Network.
MIT License
9 stars 8 forks source link

Deployment initialization order is unspecified #59

Open fulldecent opened 5 years ago

fulldecent commented 5 years ago

From https://docs.aion.network/docs/deployment-initialization

It is stated:

The <clinit> of every class submitted as part of the contract (including all the code within static {} blocks) will be run when the contract is first deployed, and never again. This makes static {} the ideal place to run any contract initialization logic.

The order of the static {} blocks should be specified.

johnnymatthews commented 5 years ago

The following snippet is from /developers/fundamentals/avm-concepts/initializable-fields.md:

Data supplied in the data field must be supplied in the exact same order as the @Initializable field are defined. If not, an ABIException will be thrown.

...

The static{} function will do the following in order:

  1. Instantiate an ABIDecoder with Blockchain.getData() and try to decode an Integer and a string;
  2. Set owner as the address that deployed the contract.
  3. Execute increaseMyIntByOne() and increase the value of myInt by one.

It looks to me that this addresses this issue. I'll leave this issue open for now for further comments however.

fulldecent commented 5 years ago

Within one contract it is clear that they are handled in the order defined.

But what is the order of the contracts?

In my test code I use

byte[] contractData = avmRule.getDappBytes(Main.class, data, AIP040Events.class, NFToken.class, NFTokenMock.class, NFTokenStorage.class, BigInteger.class);

Is that the order the the contracts are processed (and for each in the order defined in the files)? What happens if I don't have test code, is there different code that runs for deployment?