Skip to content

Commit

Permalink
[AVAX] Post Merge fixes for Cortina 15 (v1.10.15)
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Mar 7, 2024
1 parent b477865 commit d05e7ce
Show file tree
Hide file tree
Showing 37 changed files with 94 additions and 205 deletions.
4 changes: 2 additions & 2 deletions codec/reflectcodec/struct_fielder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ StructFielder = (*structFielder)(nil)
type FieldDesc struct {
Index int
MaxSliceLen uint32
Nullable bool
Nullable bool
UpgradeVersion uint16
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) (*SerializedFields,
serializedFields.Fields = append(serializedFields.Fields, FieldDesc{
Index: i,
MaxSliceLen: maxSliceLen,
Nullable: nullable,
Nullable: nullable,
UpgradeVersion: upgradeVersion,
})
}
Expand Down
2 changes: 1 addition & 1 deletion codec/reflectcodec/type_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (c *genericCodec) size(
size += wrappers.LongLen
}
}

for _, fieldDesc := range serializedFields.Fields {
if fieldDesc.UpgradeVersion > upgradeVersion {
break
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ require (

replace github.com/ava-labs/avalanche-ledger-go => github.com/chain4travel/camino-ledger-go v0.0.13-c4t

replace github.com/ava-labs/coreth => github.com/chain4travel/caminoethvm v1.1.14-rc0
replace github.com/ava-labs/coreth => github.com/chain4travel/caminoethvm v1.1.15-rc0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chain4travel/caminoethvm v1.1.14-rc0 h1:MqCeMYzPSiaJnlaapLL2RYxcnZXh34g7P0WlaUdy50E=
github.com/chain4travel/caminoethvm v1.1.14-rc0/go.mod h1:vaF3LIgjGW1povg11ZAsnY+iWMuBrhsNWz5JBtpOu80=
github.com/chain4travel/caminoethvm v1.1.15-rc0 h1:PG07uPDXzeVJzz/SH9WIjzfDKTWDyzQyh9NkEDxh5aI=
github.com/chain4travel/caminoethvm v1.1.15-rc0/go.mod h1:aXs2X5y4BVp+fGUk4sR1rk1qHmrtTl6NxTJPhUVw3P0=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/x/transfer/virtuous.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
const (
totalRounds = 50

metricBlksProcessing = "camino_X_blks_processing" //nolint:gosec
metricBlksProcessing = "camino_X_blks_processing"
metricBlksAccepted = "camino_X_blks_accepted_count"
)

Expand Down
3 changes: 2 additions & 1 deletion tools/cert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path"
"strconv"
"strings"

"github.com/decred/dcrd/dcrec/secp256k1/v4"
Expand Down Expand Up @@ -53,7 +54,7 @@ func main() {
num := ""
for i := 1; i <= count; i++ {
if count > 1 {
num = fmt.Sprintf("%d", i)
num = strconv.Itoa(i)
}

keyPath := path.Join(destPath, fmt.Sprintf(keyFile, num))
Expand Down
3 changes: 1 addition & 2 deletions utils/crypto/secp256k1/camino_secp256k1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ func newCertAndKeyBytesWithNoExt() ([]byte, []byte, error) {
}

func getPublicKey(t *testing.T, tlsCert *tls.Certificate) []byte {
secp256Factory := Factory{}
var nodePrivateKey *PrivateKey

rsaPrivateKey, ok := tlsCert.PrivateKey.(*rsa.PrivateKey)
require.True(t, ok)
secpPrivateKey := RsaPrivateKeyToSecp256PrivateKey(rsaPrivateKey)
nodePrivateKey, err := secp256Factory.ToPrivateKey(secpPrivateKey.Serialize())
nodePrivateKey, err := ToPrivateKey(secpPrivateKey.Serialize())
require.NoError(t, err)
return nodePrivateKey.PublicKey().Address().Bytes()
}
Expand Down
6 changes: 2 additions & 4 deletions utils/nodeid/camino_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat
nodeIDs := make([]ids.NodeID, localNodesCount)

for index := 0; index < localNodesCount; index++ {
secp256Factory := secp256k1.Factory{}
var nodePrivateKey *secp256k1.PrivateKey

cert, err := staking.LoadTLSCertFromFiles(
Expand All @@ -34,7 +33,7 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat
panic("Wrong private key type")
}
secpPrivateKey := secp256k1.RsaPrivateKeyToSecp256PrivateKey(rsaKey)
nodePrivateKey, err = secp256Factory.ToPrivateKey(secpPrivateKey.Serialize())
nodePrivateKey, err = secp256k1.ToPrivateKey(secpPrivateKey.Serialize())
if err != nil {
panic(err)
}
Expand All @@ -46,8 +45,7 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat
}

func GenerateCaminoNodeKeyAndID() (*secp256k1.PrivateKey, ids.NodeID) {
secp256Factory := secp256k1.Factory{}
nodePrivateKey, err := secp256Factory.NewPrivateKey()
nodePrivateKey, err := secp256k1.NewPrivateKey()
if err != nil {
panic("Couldn't generate private key")
}
Expand Down
2 changes: 1 addition & 1 deletion version/compatibility.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"30": [
"v1.10.15"
"v1.1.15"
],
"29": [
"v1.1.14",
Expand Down
15 changes: 7 additions & 8 deletions vms/platformvm/camino_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ava-labs/avalanchego/api/keystore"
"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand All @@ -28,7 +28,6 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/nodeid"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/components/avax"
as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate"
"github.com/ava-labs/avalanchego/vms/platformvm/api"
Expand Down Expand Up @@ -68,7 +67,7 @@ func defaultCaminoService(t *testing.T, camino api.Camino, utxos []api.UTXO) *Ca

vm.ctx.Lock.Lock()
defer vm.ctx.Lock.Unlock()
ks := keystore.New(logging.NoLog{}, manager.NewMemDB(version.Semantic1_0_0))
ks := keystore.New(logging.NoLog{}, memdb.New())
require.NoError(t, ks.CreateUser(testUsername, testPassword))
vm.ctx.Keystore = ks.NewBlockchainKeyStore(vm.ctx.ChainID)
return &CaminoService{
Expand All @@ -84,9 +83,9 @@ func newCaminoVM(t *testing.T, genesisConfig api.Camino, genesisUTXOs []api.UTXO

vm := &VM{Config: defaultCaminoConfig()}

baseDBManager := manager.NewMemDB(version.Semantic1_0_0)
chainDBManager := baseDBManager.NewPrefixDBManager([]byte{0})
atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database)
db := memdb.New()
chainDB := prefixdb.New([]byte{0}, db)
atomicDB := prefixdb.New([]byte{1}, db)

if startTime == nil {
startTime = &defaultStartTime
Expand Down Expand Up @@ -114,7 +113,7 @@ func newCaminoVM(t *testing.T, genesisConfig api.Camino, genesisUTXOs []api.UTXO
require.NoError(vm.Initialize(
context.Background(),
ctx,
chainDBManager,
chainDB,
genesisBytes,
nil,
nil,
Expand Down Expand Up @@ -239,7 +238,7 @@ func newCaminoGenesisWithUTXOs(t *testing.T, caminoGenesisConfig api.Camino, gen

func generateKeyAndOwner(t *testing.T) (*secp256k1.PrivateKey, ids.ShortID, secp256k1fx.OutputOwners) {
t.Helper()
key, err := testKeyFactory.NewPrivateKey()
key, err := secp256k1.NewPrivateKey()
require.NoError(t, err)
addr := key.Address()
return key, addr, secp256k1fx.OutputOwners{
Expand Down
8 changes: 4 additions & 4 deletions vms/platformvm/camino_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ utxoFor:
continue utxoFor
}

utxoIDs = append(utxoIDs, &utxo.UTXOID) //nolint:gosec
utxoIDs = append(utxoIDs, &utxo.UTXOID)
}

response.camino = GetBalanceResponseV2{balances, unlockedOutputs, bondedOutputs, depositedOutputs, depositedBondedOutputs, utxoIDs}
Expand Down Expand Up @@ -601,7 +601,7 @@ func (s *CaminoService) Claim(_ *http.Request, args *ClaimArgs, reply *api.JSONT
type TransferArgs struct {
api.UserPass
api.JSONFromAddrs
Change platformapi.Owner `json:"change"`
Change string `json:"change"`
TransferTo platformapi.Owner `json:"transferTo"`
Amount json.Uint64 `json:"amount"`
}
Expand All @@ -618,7 +618,7 @@ func (s *CaminoService) Transfer(_ *http.Request, args *TransferArgs, reply *api
return err
}

change, err := s.secpOwnerFromAPI(&args.Change)
_, change, err := s.addrManager.ParseAddress(args.Change)
if err != nil {
return fmt.Errorf(errInvalidChangeAddr, err)
}
Expand All @@ -631,7 +631,7 @@ func (s *CaminoService) Transfer(_ *http.Request, args *TransferArgs, reply *api
// Create the transaction
tx, err := s.vm.txBuilder.NewBaseTx(
uint64(args.Amount),
transferTo,
*transferTo,
privKeys,
change,
)
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/camino_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestRemoveDeferredValidator(t *testing.T) {

rootAdminKey := caminoPreFundedKeys[0]
adminProposerKey := caminoPreFundedKeys[0]
consortiumMemberKey, err := testKeyFactory.NewPrivateKey()
consortiumMemberKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

outputOwners := &secp256k1fx.OutputOwners{
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestRemoveReactivatedValidator(t *testing.T) {

rootAdminKey := caminoPreFundedKeys[0]
adminProposerKey := caminoPreFundedKeys[0]
consortiumMemberKey, err := testKeyFactory.NewPrivateKey()
consortiumMemberKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

outputOwners := &secp256k1fx.OutputOwners{
Expand Down
11 changes: 0 additions & 11 deletions vms/platformvm/metrics/camino_tx_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type caminoTxMetrics struct {
numClaimTxs,
numRegisterNodeTxs,
numRewardsImportTxs,
numBaseTxs,
numMultisigAliasTxs,
numAddDepositOfferTxs,
numAddProposalTxs,
Expand All @@ -47,7 +46,6 @@ func newCaminoTxMetrics(
numClaimTxs: newTxMetric(namespace, "claim", registerer, &errs),
numRegisterNodeTxs: newTxMetric(namespace, "register_node", registerer, &errs),
numRewardsImportTxs: newTxMetric(namespace, "rewards_import", registerer, &errs),
numBaseTxs: newTxMetric(namespace, "base", registerer, &errs),
numMultisigAliasTxs: newTxMetric(namespace, "multisig_alias", registerer, &errs),
numAddDepositOfferTxs: newTxMetric(namespace, "add_deposit_offer", registerer, &errs),
numAddProposalTxs: newTxMetric(namespace, "add_proposal", registerer, &errs),
Expand Down Expand Up @@ -83,10 +81,6 @@ func (*txMetrics) RewardsImportTx(*txs.RewardsImportTx) error {
return nil
}

func (*txMetrics) BaseTx(*txs.BaseTx) error {
return nil
}

func (*txMetrics) MultisigAliasTx(*txs.MultisigAliasTx) error {
return nil
}
Expand Down Expand Up @@ -139,11 +133,6 @@ func (m *caminoTxMetrics) RewardsImportTx(*txs.RewardsImportTx) error {
return nil
}

func (m *caminoTxMetrics) BaseTx(*txs.BaseTx) error {
m.numBaseTxs.Inc()
return nil
}

func (m *caminoTxMetrics) MultisigAliasTx(*txs.MultisigAliasTx) error {
m.numMultisigAliasTxs.Inc()
return nil
Expand Down
12 changes: 4 additions & 8 deletions vms/platformvm/state/camino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/database/versiondb"
root_genesis "github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/components/avax"
as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate"
"github.com/ava-labs/avalanchego/vms/platformvm/deposit"
pvm_genesis "github.com/ava-labs/avalanchego/vms/platformvm/genesis"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

db_manager "github.com/ava-labs/avalanchego/database/manager"
)

const (
Expand Down Expand Up @@ -167,9 +164,8 @@ func getExpectedSupply(
func TestSyncGenesis(t *testing.T) {
require := require.New(t)
s, _ := newInitializedState(require)
baseDBManager := db_manager.NewMemDB(version.Semantic1_0_0)
baseDB := versiondb.New(baseDBManager.Current().Database)
validatorsDB := prefixdb.New(validatorsPrefix, baseDB)
db := memdb.New()
validatorsDB := prefixdb.New(validatorsPrefix, db)

var (
id = ids.GenerateTestID()
Expand Down Expand Up @@ -255,7 +251,7 @@ func TestSyncGenesis(t *testing.T) {
},
}, depositTxs, initialAdmin),
},
cs: *wrappers.IgnoreError(newCaminoState(baseDB, validatorsDB, prometheus.NewRegistry())).(*caminoState),
cs: *wrappers.IgnoreError(newCaminoState(db, validatorsDB, prometheus.NewRegistry())).(*caminoState),
want: caminoDiff{
modifiedAddressStates: map[ids.ShortID]as.AddressState{initialAdmin: as.AddressStateRoleAdmin, shortID: as.AddressStateRoleKYC},
modifiedDepositOffers: map[ids.ID]*deposit.Offer{
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/state/mock_chain.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vms/platformvm/state/mock_diff.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vms/platformvm/state/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vms/platformvm/txs/base_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestBaseTxSerialization(t *testing.T) {
// Codec version
0x00, 0x00,
// BaseTx Type ID
0x00, 0x00, 0x00, 0x22,
0x00, 0x00, 0x20, 0x8,
// Mainnet network ID
0x00, 0x00, 0x00, 0x01,
// P-chain blockchain ID
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestBaseTxSerialization(t *testing.T) {
// Codec version
0x00, 0x00,
// BaseTx Type ID
0x00, 0x00, 0x00, 0x22,
0x00, 0x00, 0x20, 0x8,
// Mainnet network ID
0x00, 0x00, 0x00, 0x01,
// P-chain blockchain ID
Expand Down
Loading

0 comments on commit d05e7ce

Please sign in to comment.