platformvm/config: preserve nanosecond Duration wire format for v2

v1 encoding/json marshaled time.Duration as an integer count of
nanoseconds by default; v2 has no default Duration representation and
returns a SemanticError unless told otherwise. The PlatformVM
configuration (Network, ExecutionConfig) has been on-disk-stable as
integer nanoseconds since launch — keep that wire format by passing
jsonv1.FormatDurationAsNano(true) at the Marshal/Unmarshal call sites
in GetConfig, GetExecutionConfig, and the corresponding tests that
prepare fixtures via json.Marshal.
This commit is contained in:
Hanzo AI
2026-06-06 23:06:21 -07:00
parent e7677edfd8
commit 6bc6ca2e69
4 changed files with 8 additions and 4 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ package config
import (
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"time"
"github.com/luxfi/constants"
@@ -78,5 +79,5 @@ func GetConfig(b []byte) (*Config, error) {
return &ec, nil
}
return &ec, json.Unmarshal(b, &ec)
return &ec, json.Unmarshal(b, &ec, jsonv1.FormatDurationAsNano(true))
}
+2 -1
View File
@@ -5,6 +5,7 @@ package config
import (
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"reflect"
"testing"
"time"
@@ -119,7 +120,7 @@ func TestConfigUnmarshal(t *testing.T) {
verifyInitializedStruct(t, *expected)
verifyInitializedStruct(t, expected.Network)
b, err := json.Marshal(expected)
b, err := json.Marshal(expected, jsonv1.FormatDurationAsNano(true))
require.NoError(err)
actual, err := GetConfig(b)
+2 -1
View File
@@ -5,6 +5,7 @@ package config
import (
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"time"
"github.com/luxfi/constants"
@@ -50,5 +51,5 @@ func GetExecutionConfig(b []byte) (*ExecutionConfig, error) {
return &ec, nil
}
return &ec, json.Unmarshal(b, &ec)
return &ec, json.Unmarshal(b, &ec, jsonv1.FormatDurationAsNano(true))
}
@@ -5,6 +5,7 @@ package config
import (
"github.com/go-json-experiment/json"
jsonv1 "github.com/go-json-experiment/json/v1"
"testing"
"time"
@@ -77,7 +78,7 @@ func TestExecutionConfigUnmarshal(t *testing.T) {
verifyInitializedStruct(t, *expected)
verifyInitializedStruct(t, expected.Network)
b, err := json.Marshal(expected)
b, err := json.Marshal(expected, jsonv1.FormatDurationAsNano(true))
require.NoError(err)
actual, err := GetExecutionConfig(b)