Skip to content

Commit

Permalink
Merge branch 'master' into update-versions-v1.11.10
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jul 25, 2024
2 parents 9c5bda8 + 57fb839 commit 532a1a7
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 134 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run fuzz tests

on:
schedule:
- cron: "0 0 * * *"
- cron: "0 0 * * *" # Once a day at midnight UTC

permissions:
contents: read
Expand All @@ -13,8 +13,6 @@ jobs:
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
ref: 'dev'
- name: Set up Go
uses: ./.github/actions/setup-go-for-project
- name: Run fuzz tests
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/fuzz_merkledb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
ref: 'dev'
- name: Set up Go
uses: ./.github/actions/setup-go-for-project
- name: Run merkledb fuzz tests
Expand Down
38 changes: 37 additions & 1 deletion genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils"
Expand All @@ -21,6 +22,8 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
)

const localNetworkUpdateStartTimePeriod = 9 * 30 * 24 * time.Hour // 9 months

var (
_ utils.Sortable[Allocation] = Allocation{}

Expand Down Expand Up @@ -170,6 +173,10 @@ var (
// LocalConfig is the config that should be used to generate a local
// genesis.
LocalConfig Config

// unmodifiedLocalConfig is the LocalConfig before advancing the StartTime
// to a recent value.
unmodifiedLocalConfig Config
)

func init() {
Expand All @@ -196,10 +203,21 @@ func init() {
panic(err)
}

LocalConfig, err = unparsedLocalConfig.Parse()
unmodifiedLocalConfig, err = unparsedLocalConfig.Parse()
if err != nil {
panic(err)
}

// Renew the staking start time of the local config if required
definedStartTime := time.Unix(int64(unmodifiedLocalConfig.StartTime), 0)
recentStartTime := getRecentStartTime(
definedStartTime,
time.Now(),
localNetworkUpdateStartTimePeriod,
)

LocalConfig = unmodifiedLocalConfig
LocalConfig.StartTime = uint64(recentStartTime.Unix())
}

func GetConfig(networkID uint32) *Config {
Expand Down Expand Up @@ -247,3 +265,21 @@ func parseGenesisJSONBytesToConfig(bytes []byte) (*Config, error) {
}
return &config, nil
}

// getRecentStartTime advances [definedStartTime] in chunks of [period]. It
// returns the latest startTime that isn't after [now].
func getRecentStartTime(
definedStartTime time.Time,
now time.Time,
period time.Duration,
) time.Time {
startTime := definedStartTime
for {
nextStartTime := startTime.Add(period)
if now.Before(nextStartTime) {
break
}
startTime = nextStartTime
}
return startTime
}
66 changes: 66 additions & 0 deletions genesis/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package genesis

import (
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -51,3 +52,68 @@ func TestAllocationCompare(t *testing.T) {
})
}
}

func TestGetRecentStartTime(t *testing.T) {
type test struct {
name string
defined time.Time
now time.Time
expected time.Time
}
tests := []test{
{
name: "before 1 period and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(-localNetworkUpdateStartTimePeriod - time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "before 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(-time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "equal",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "after 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "after 1 period",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
},
{
name: "after 1 period and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod + time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
},
{
name: "after 2 periods",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
},
{
name: "after 2 periods and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2*localNetworkUpdateStartTimePeriod + time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := getRecentStartTime(tt.defined, tt.now, localNetworkUpdateStartTimePeriod)
require.Equal(t, tt.expected, actual)
})
}
}
4 changes: 2 additions & 2 deletions genesis/genesis_local.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]
}
],
"startTime": 1690862400,
"startTime": 1721016000,
"initialStakeDuration": 31536000,
"initialStakeDurationOffset": 5400,
"initialStakedFunds": [
Expand Down Expand Up @@ -93,4 +93,4 @@
],
"cChainGenesis": "{\"config\":{\"chainId\":43112,\"homesteadBlock\":0,\"daoForkBlock\":0,\"daoForkSupport\":true,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"apricotPhase1BlockTimestamp\":0,\"apricotPhase2BlockTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x5f5e100\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC\":{\"balance\":\"0x295BE96E64066972000000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}",
"message": "{{ fun_quote }}"
}
}
15 changes: 7 additions & 8 deletions genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,27 @@ func TestGenesisFromFlag(t *testing.T) {

func TestGenesis(t *testing.T) {
tests := []struct {
networkID uint32
config *Config
expectedID string
}{
{
networkID: constants.MainnetID,
config: &MainnetConfig,
expectedID: "UUvXi6j7QhVvgpbKM89MP5HdrxKm9CaJeHc187TsDNf8nZdLk",
},
{
networkID: constants.FujiID,
config: &FujiConfig,
expectedID: "MSj6o9TpezwsQx4Tv7SHqpVvCbJ8of1ikjsqPZ1bKRjc9zBy3",
},
{
networkID: constants.LocalID,
expectedID: "S4BvHv1XyihF9gXkJKXWWwQuuDWZqesRXz6wnqavQ9FrjGfAa",
config: &unmodifiedLocalConfig,
expectedID: "23DnViuN2kgePiBN4JxZXh1VrfXca2rwUp6XrKgNGdj3TSQjiN",
},
}
for _, test := range tests {
t.Run(constants.NetworkIDToNetworkName[test.networkID], func(t *testing.T) {
t.Run(constants.NetworkIDToNetworkName[test.config.NetworkID], func(t *testing.T) {
require := require.New(t)

config := GetConfig(test.networkID)
genesisBytes, _, err := FromConfig(config)
genesisBytes, _, err := FromConfig(test.config)
require.NoError(err)

var genesisID ids.ID = hashing.ComputeHash256Array(genesisBytes)
Expand Down
54 changes: 54 additions & 0 deletions vms/platformvm/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,60 @@ Testnet: U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK

:::

### `platform.getSubnet`

Get owners and elastic info about the Subnet.

**Signature:**

```sh
platform.getSubnet({
subnetID: string
}) ->
{
isPermissioned: bool,
controlKeys: []string,
threshold: string,
locktime: string,
subnetTransformationTxID: string
}
```

- `subnetID` is the ID of the Subnet to get information about. If omitted, fails.
- `threshold` signatures from addresses in `controlKeys` are needed to make changes to
a permissioned subnet. If the Subnet is a PoS Subnet, then `threshold` will be `0` and `controlKeys`
will be empty.
- changes can not be made into the subnet until `locktime` is in the past.
- `subnetTransformationTxID` is the ID of the transaction that changed the subnet into a elastic one,
for when this change was performed.

**Example Call:**

```sh
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "platform.getSubnet",
"params": {"subnetID":"Vz2ArUpigHt7fyE79uF3gAXvTPLJi2LGgZoMpgNPHowUZJxBb"},
"id": 1
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/P
```

**Example Response:**

```json
{
"jsonrpc": "2.0",
"result": {
"isPermissioned": true,
"controlKeys": ["P-fuji1ztvstx6naeg6aarfd047fzppdt8v4gsah88e0c","P-fuji193kvt4grqewv6ce2x59wnhydr88xwdgfcedyr3"],
"threshold": "1",
"locktime": "0",
"subnetTransformationTxID": "11111111111111111111111111111111LpoYY"
},
"id": 1
}
```

### `platform.getSubnets`

:::caution
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/warp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Once the validator set of a blockchain is willing to sign an arbitrary message `

## Verifying / Receiving an Avalanche Warp Message

Avalanache Warp Messages are verified within the context of a specific P-Chain height included in the [ProposerVM](../../proposervm/README.md)'s header. The P-Chain height is provided as context to the underlying VM when verifying the underlying VM's blocks (implemented by the optional interface [WithVerifyContext](../../../snow/engine/snowman/block/block_context_vm.go)).
Avalanche Warp Messages are verified within the context of a specific P-Chain height included in the [ProposerVM](../../proposervm/README.md)'s header. The P-Chain height is provided as context to the underlying VM when verifying the underlying VM's blocks (implemented by the optional interface [WithVerifyContext](../../../snow/engine/snowman/block/block_context_vm.go)).

To verify the message, the underlying VM utilizes this `warp` package to perform the following steps:

Expand Down
Loading

0 comments on commit 532a1a7

Please sign in to comment.