You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`SmartContractRegistration` entity can be fetched by the hash value of the contract code. In fact, it is only written once when deploying the contract.
38
+
39
+
The data structure that corresponds one-to-one with contracts is called `ContractInfo`.
40
+
Structure `ContractInfo` is defined in `acs0.proto`.
41
+
42
+
```C#
43
+
messageContractInfo
44
+
{
45
+
// The serial number of the contract.
46
+
int64serial_number=1;
47
+
// The author of the contract, this is the person who deployed the contract.
48
+
aelf.Addressauthor=2;
49
+
// The category of contract code(0: C#).
50
+
sint32category=3;
51
+
// The hash of the contract code.
52
+
aelf.Hashcode_hash=4;
53
+
// Whether it is a system contract.
54
+
boolis_system_contract=5;
55
+
// The version of the current contract.
56
+
int32version=6;
57
+
stringcontract_version=7;
58
+
// Indicates if the contract is the user contract.
59
+
boolis_user_contract=8;
60
+
}
61
+
```
62
+
63
+
We use the MappedState to store related instances.
From the `code_hash` field of `ContractInfo`, it is not difficult to guess:
70
+
71
+
1. When trying to retrieve the contract code, the `code_hash` of ContractInfo is first read, and then the contract code itself is read from `State.SmartContractRegistrations` mapped state.
72
+
2. Upgrading a contract on aelf is actually replacing the `code_hash` of `ContractInfo`.
73
+
74
+
# Calculation of contract address
75
+
76
+
The contract address is actually calculated through a field that increases with the number of contract deployments.
- The contract address of each chain of aelf is different.
89
+
- The contract address is not related to the contract code, but only to the order in which it is deployed on this chain.
90
+
- Therefore, when testing newly written contracts in `aelf-boilerplate` or `aelf-developer-tools`, the new contract always has a fixed address.
91
+
92
+
After the 1.6.0 version, Salt is added to the imported parameter of the deployment/upgrade contract. The contract address is calculated by using the Deployer address of the deployment account and the hash value Salt.
- Deploying contracts with the same account and using the same Salt can make the contract address of each chain of aelf the same.
99
+
100
+
# Contract deployment and update process
101
+
102
+
## Deploy contract with audit
103
+
104
+
The current pipeline starts with Propose, which generates a parliamentary proposal.
105
+
When more than 2/3 of the BPs agree to deploy/update, a new proposal is released to request code inspection.
106
+
Finally, after the code inspection is passed, the real contract deployment/upgrade will be achieved through the proposal of releasing code inspection.
107
+
108
+
## Deploy contract without audit
109
+
110
+
Developers send deployment/update user contract transactions, generate a parliamentary CodeCheck proposal, and when more than 2/3 of the BPs conduct code checks and pass, achieve real contract deployment/upgrade through the proposal of automatically releasing code checks.
111
+
112
+
## Contract deployment and upgrade new version number
113
+
114
+
When upgrading a contract, check the contract version information
115
+
- If the contract version is less than or equal to the original contract version, the upgrade contract transaction fails
116
+
The old version of the contract only has a version number after being upgraded.
117
+
- If the version number is increasing , the upgrade contract transaction is successful.
118
+
119
+
In the updateSmartContract method, increase the version number judgment:
$"The version to be deployed is lower than the effective version({info.ContractVersion}), please correct the version number.");
125
+
```
126
+
127
+
# Contract error message
128
+
129
+
130
+
| Method | Error message | Note |
131
+
| --- | --- | --- |
132
+
| DeployUserSmartContract | No permission. | Trying to deploy smart contract to an aelf private sidechain, and the transaction sender is not in allowlist. |
133
+
|| contract code has already been deployed before. | Contract code deployed |
| UpdateUserSmartContract | Contract not found. | Contract does not exist |
136
+
|| No permission. | The updated contract author is not myself |
137
+
|| Code is not changed. | The contract code has not changed |
138
+
|| contract code has already been deployed before. | Contract code deployed |
139
+
|| The version to be deployed is lower than the effective version({currentVersion}), please correct the version number. | Updated contract version number is too low |
0 commit comments