Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Update kip149
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis committed Oct 10, 2023
1 parent 8f8fda4 commit cd22ff4
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions KIPs/kip-149.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This standard defines the separation of data and logic contracts in system contr

### Definitions

- System contract: A contract that affects protocol. The currently deployed system contracts are as follows: **AddressBook**, **Voting**([KIP-81](https://github.com/klaytn/kips/blob/main/KIPs/kip-81.md)), **StakingTracker**, **TreasuryRebalance**([KIP-103](https://github.com/klaytn/kips/blob/main/KIPs/kip-103.md))
- System contract: A contract that affects protocol. The currently deployed system contracts are as follows: **AddressBook**, **GovParam**, **Voting**([KIP-81](https://github.com/klaytn/kips/blob/main/KIPs/kip-81.md)), **StakingTracker**, **TreasuryRebalance**([KIP-103](https://github.com/klaytn/kips/blob/main/KIPs/kip-103.md))

- System contract upgrade: The process of updating an existing logic contract while maintaining a proxy contract. The upgraded logic contract must be compatible with the previous interface.

Expand Down Expand Up @@ -172,18 +172,48 @@ After a target block number, a Klaytn node should read all the active addresses

In the Chain Config, the following field is introduced. All node operators in a network must update `genesis.json` configuration with the same value. The configuration values for Baobab and Cypress networks are hard-coded on the client source code.

- `registryAddress`: the reserved address for the Registry contract, which is `0x0000000000000000000000000000000000000401`.
- `RegistryAddress`: the reserved address for the Registry contract, which is `0x0000000000000000000000000000000000000401`.

- `Kip149CompatibleBlock`: the target block number that a Klaytn node deploys Registry.

- `RegistryConfig`: the initial data config for the Registry. It is used when injecting the initial state after deploying the Registry.

```go
// In klaytn/params/config.go
type RegistryConfig struct {
Records map[string][]common.Address // Map for pre-deployed system contracts
Owner common.Address // Address for initial owner of Registry
}

var ChainConfig = &ChainConfig{
...
RegistryAddress: common.HexToAddress("0x0000000000000000000000000000000000000401"),
Kip149CompatibleBlock: TBD,
// RegistryInit will be used when injecting initial state for the Registry
RegistryInit: &RegistryConfig{
Records: map[string][]common.Address{
"AddressBook": {
AddressBookAddress,
},
"TreasuryRebalance": {
KIP103Address,
},
...
},
Owner: OwnerAddress,
},
}
```

- `kip149CompatibleBlock`: the target block number that a Klaytn node deploys Registry.

#### Execution

The Registry deployment is executed at the `Finalize` function, which means the end of the block generation. It reads the reserved address and runtime bytecode and deploys the Registry by the bytecode injection. Also, it injects the state for pre-deployed system contracts here. Note that the Registry contract will be deployed at th parent block of the `kip149CompatibleBlock` since it needs to be ready at the `kip149CompatibleBlock`.
The Registry deployment is executed at the `Finalize` function, which means the end of the block generation. It reads the reserved address and runtime bytecode and deploys the Registry by the bytecode injection. Also, it injects the initial state provided by `RegistryConfig` for the Registry here. Note that the Registry contract will be deployed at th parent block of the `kip149CompatibleBlock` since it needs to be ready at the `kip149CompatibleBlock`.

```go
// Note that it is deployed at the parent block of the kip-149 fork block
if chain.Config().IsKIP149ForkBlockParent(header.Number) {
// Inject the bytecode for the Registry contract and the state for pre-deployed system contracts
// Inject the bytecode for the Registry and the state of owner and pre-deployed system contracts
err := registry.InstallRegistry(state)
if err != nil {
logger.Error("failed to set the registry contract code", "err", err)
Expand Down

0 comments on commit cd22ff4

Please sign in to comment.