diff --git a/analyzer/consensus/consensus.go b/analyzer/consensus/consensus.go index 1019c9e86..d88f871bd 100644 --- a/analyzer/consensus/consensus.go +++ b/analyzer/consensus/consensus.go @@ -15,18 +15,33 @@ import ( coreCommon "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/oasis-core/go/common/cbor" "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" + "github.com/oasisprotocol/oasis-core/go/common/entity" sdkConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config" - "github.com/oasisprotocol/nexus/common" + beaconCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/beacon/api" + governanceCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/governance/api" + registryCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/registry/api" + roothashCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/roothash/api" + + beacon "github.com/oasisprotocol/nexus/coreapi/v22.2.11/beacon/api" + "github.com/oasisprotocol/nexus/coreapi/v22.2.11/common/node" "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api/transaction" genesis "github.com/oasisprotocol/nexus/coreapi/v22.2.11/genesis/api" + governance "github.com/oasisprotocol/nexus/coreapi/v22.2.11/governance/api" + keymanager "github.com/oasisprotocol/nexus/coreapi/v22.2.11/keymanager/api" + registry "github.com/oasisprotocol/nexus/coreapi/v22.2.11/registry/api" + roothash "github.com/oasisprotocol/nexus/coreapi/v22.2.11/roothash/api" staking "github.com/oasisprotocol/nexus/coreapi/v22.2.11/staking/api" + consensusEden "github.com/oasisprotocol/nexus/coreapi/v23.0/consensus/api" + keymanagerEden "github.com/oasisprotocol/nexus/coreapi/v23.0/keymanager/api" + "github.com/oasisprotocol/nexus/analyzer" "github.com/oasisprotocol/nexus/analyzer/block" "github.com/oasisprotocol/nexus/analyzer/queries" "github.com/oasisprotocol/nexus/analyzer/util" apiTypes "github.com/oasisprotocol/nexus/api/v1/types" + "github.com/oasisprotocol/nexus/common" "github.com/oasisprotocol/nexus/config" "github.com/oasisprotocol/nexus/log" "github.com/oasisprotocol/nexus/metrics" @@ -38,6 +53,46 @@ const ( consensusAnalyzerName = "consensus" ) +// The Cobalt (v21.1.1) version of oasis-core defines some transaction structs +// that are incompatible with the structs used in Damask onwards. We track +// those structs here and use them as a backup if the initial unmarshalling fails. +var bodyTypeForTxMethodCobalt = map[string]interface{}{ + "governance.SubmitProposal": governanceCobalt.ProposalContent{}, + "registry.DeregisterEntity": nil, + "registry.RegisterRuntime": registryCobalt.Runtime{}, + "roothash.ExecutorCommit": roothashCobalt.ExecutorCommit{}, + "roothash.Evidence": roothashCobalt.Evidence{}, +} + +var bodyTypeForTxMethod = map[string]interface{}{ + "beacon.PVSSCommit": beaconCobalt.PVSSCommit{}, + "beacon.PVSSReveal": beaconCobalt.PVSSReveal{}, + "beacon.VRFProve": beacon.VRFProve{}, + "consensus.Meta": consensusEden.BlockMetadata{}, + "governance.SubmitProposal": governance.ProposalContent{}, + "governance.CastVote": governance.ProposalVote{}, + "keymanager.PublishMasterSecret": keymanagerEden.SignedEncryptedMasterSecret{}, + "keymanager.PublishEphemeralSecret": keymanagerEden.SignedEncryptedEphemeralSecret{}, + "keymanager.UpdatePolicy": keymanager.SignedPolicySGX{}, + "registry.RegisterEntity": entity.SignedEntity{}, + "registry.DeregisterEntity": registry.DeregisterEntity{}, + "registry.RegisterNode": node.MultiSignedNode{}, + "registry.UnfreezeNode": registry.UnfreezeNode{}, + "registry.RegisterRuntime": registry.Runtime{}, + "registry.ProveFreshness": registry.Runtime{}, + "roothash.ExecutorCommit": roothash.ExecutorCommit{}, + "roothash.ExecutorProposerTimeout": roothash.ExecutorProposerTimeoutRequest{}, + "roothash.Evidence": roothash.Evidence{}, + "roothash.SubmitMsg": roothash.SubmitMsg{}, + "staking.Transfer": staking.Transfer{}, + "staking.Burn": staking.Burn{}, + "staking.AddEscrow": staking.Escrow{}, + "staking.ReclaimEscrow": staking.ReclaimEscrow{}, + "staking.AmendCommissionSchedule": staking.AmendCommissionSchedule{}, + "staking.Allow": staking.Allow{}, + "staking.Withdraw": staking.Withdraw{}, +} + type EventType = apiTypes.ConsensusEventType // alias for brevity type parsedEvent struct { @@ -380,15 +435,24 @@ func (m *processor) queueEpochInserts(batch *storage.QueryBatch, data *consensus // Adapted from https://github.com/oasisprotocol/oasis-core/blob/master/go/consensus/api/transaction/transaction.go#L58 func unpackTxBody(t *transaction.Transaction) (interface{}, error) { - bodyType := t.Method.BodyType() - if bodyType == nil { + bodyType, ok := bodyTypeForTxMethod[string(t.Method)] + if !ok { return nil, fmt.Errorf("unknown method body: %s", t.Method) } // Deserialize into correct type. v := reflect.New(reflect.TypeOf(bodyType)).Interface() if err := cbor.Unmarshal(t.Body, v); err != nil { - return nil, fmt.Errorf("unable to cbor-decode consensus tx body: %w, body: %s", err, base64.StdEncoding.EncodeToString(t.Body)) + // This may be an older tx from Cobalt; attempt to unmarshal into + // the appropriate Cobalt tx type. + bodyType, ok = bodyTypeForTxMethodCobalt[string(t.Method)] + if !ok { + return nil, fmt.Errorf("unable to cbor-decode consensus tx body: %w, body: %s", err, base64.StdEncoding.EncodeToString(t.Body)) + } + v = reflect.New(reflect.TypeOf(bodyType)).Interface() + if err = cbor.Unmarshal(t.Body, v); err != nil { + return nil, fmt.Errorf("unable to cbor-decode consensus tx body into Cobalt type: %w, body: %s", err, base64.StdEncoding.EncodeToString(t.Body)) + } } return v, nil diff --git a/coreapi/v22.2.11/beacon/api/vrf.go b/coreapi/v22.2.11/beacon/api/vrf.go index 0b9a5ff2d..5331c03d2 100644 --- a/coreapi/v22.2.11/beacon/api/vrf.go +++ b/coreapi/v22.2.11/beacon/api/vrf.go @@ -9,9 +9,6 @@ import ( // GasOpVRFProve is the gas operation identifier for VRF proof submission. const GasOpVRFProve transaction.Op = "vrf_prove" -// MethodVRFProve is the method name for a VRF proof. -var MethodVRFProve = transaction.NewMethodName(ModuleName, "VRFProve", VRFProve{}) - // removed var block // VRFParameters are the beacon parameters for the VRF backend. diff --git a/coreapi/v22.2.11/consensus/api/transaction/transaction.go b/coreapi/v22.2.11/consensus/api/transaction/transaction.go index 66368dd71..4a788aca0 100644 --- a/coreapi/v22.2.11/consensus/api/transaction/transaction.go +++ b/coreapi/v22.2.11/consensus/api/transaction/transaction.go @@ -1,9 +1,6 @@ package transaction import ( - "fmt" - "sync" - "github.com/oasisprotocol/oasis-core/go/common/cbor" "github.com/oasisprotocol/oasis-core/go/common/crypto/hash" "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" @@ -13,9 +10,6 @@ import ( const moduleName = "consensus/transaction" // removed var block -var ( - registeredMethods sync.Map -) // Transaction is an unsigned consensus transaction. type Transaction struct { @@ -119,10 +113,7 @@ type MethodName string // removed func // BodyType returns the registered body type associated with this method. -func (m MethodName) BodyType() interface{} { - bodyType, _ := registeredMethods.Load(string(m)) - return bodyType -} +// removed func // Metadata returns the method metadata. // removed func @@ -134,15 +125,7 @@ func (m MethodName) BodyType() interface{} { // // Module and method pair must be unique. If they are not, this method // will panic. -func NewMethodName(module, method string, bodyType interface{}) MethodName { - // Check for duplicate method names. - name := module + MethodSeparator + method - if _, isRegistered := registeredMethods.LoadOrStore(name, bodyType); isRegistered { - panic(fmt.Errorf("transaction: method already registered: %s", name)) - } - - return MethodName(name) -} +// removed func // Proof is a proof of transaction inclusion in a block. type Proof struct { diff --git a/coreapi/v22.2.11/governance/api/api.go b/coreapi/v22.2.11/governance/api/api.go index 3cbb0443e..be0b740d1 100644 --- a/coreapi/v22.2.11/governance/api/api.go +++ b/coreapi/v22.2.11/governance/api/api.go @@ -19,13 +19,6 @@ const ModuleName = "governance" // ProposalContent. const ProposalContentInvalidText = "(invalid)" -var ( - // MethodSubmitProposal submits a new consensus layer governance proposal. - MethodSubmitProposal = transaction.NewMethodName(ModuleName, "SubmitProposal", ProposalContent{}) - // MethodCastVote casts a vote for a consensus layer governance proposal. - MethodCastVote = transaction.NewMethodName(ModuleName, "CastVote", ProposalVote{}) -) - // removed var block // ProposalContent is a consensus layer governance proposal content. diff --git a/coreapi/v22.2.11/keymanager/api/api.go b/coreapi/v22.2.11/keymanager/api/api.go index bfc305227..5cf104c85 100644 --- a/coreapi/v22.2.11/keymanager/api/api.go +++ b/coreapi/v22.2.11/keymanager/api/api.go @@ -4,8 +4,6 @@ package api import ( "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/oasis-core/go/common/crypto/signature" - - "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api/transaction" ) const ( @@ -16,11 +14,6 @@ const ( ChecksumSize = 32 ) -var ( - // MethodUpdatePolicy is the method name for policy updates. - MethodUpdatePolicy = transaction.NewMethodName(ModuleName, "UpdatePolicy", SignedPolicySGX{}) -) - // removed var block // Status is the current key manager status. diff --git a/coreapi/v22.2.11/registry/api/api.go b/coreapi/v22.2.11/registry/api/api.go index 1068a1d6a..eddb7d0fa 100644 --- a/coreapi/v22.2.11/registry/api/api.go +++ b/coreapi/v22.2.11/registry/api/api.go @@ -30,19 +30,6 @@ var ( // RegisterNodeSignatureContext is the context used for node // registration. RegisterNodeSignatureContext = original.RegisterNodeSignatureContext - - // MethodRegisterEntity is the method name for entity registrations. - MethodRegisterEntity = transaction.NewMethodName(ModuleName, "RegisterEntity", entity.SignedEntity{}) - // MethodDeregisterEntity is the method name for entity deregistrations. - MethodDeregisterEntity = transaction.NewMethodName(ModuleName, "DeregisterEntity", DeregisterEntity{}) - // MethodRegisterNode is the method name for node registrations. - MethodRegisterNode = transaction.NewMethodName(ModuleName, "RegisterNode", node.MultiSignedNode{}) - // MethodUnfreezeNode is the method name for unfreezing nodes. - MethodUnfreezeNode = transaction.NewMethodName(ModuleName, "UnfreezeNode", UnfreezeNode{}) - // MethodRegisterRuntime is the method name for registering runtimes. - MethodRegisterRuntime = transaction.NewMethodName(ModuleName, "RegisterRuntime", Runtime{}) - // MethodProveFreshness is the method name for freshness proofs. - MethodProveFreshness = transaction.NewMethodName(ModuleName, "ProveFreshness", Runtime{}) ) // Backend is a registry implementation. diff --git a/coreapi/v22.2.11/roothash/api/api.go b/coreapi/v22.2.11/roothash/api/api.go index 4389444be..f5e091546 100644 --- a/coreapi/v22.2.11/roothash/api/api.go +++ b/coreapi/v22.2.11/roothash/api/api.go @@ -37,20 +37,6 @@ const ( LogEventHistoryReindexing = "roothash/history_reindexing" ) -var ( - // MethodExecutorCommit is the method name for executor commit submission. - MethodExecutorCommit = transaction.NewMethodName(ModuleName, "ExecutorCommit", ExecutorCommit{}) - - // MethodExecutorProposerTimeout is the method name for executor proposer timeout. - MethodExecutorProposerTimeout = transaction.NewMethodName(ModuleName, "ExecutorProposerTimeout", ExecutorProposerTimeoutRequest{}) - - // MethodEvidence is the method name for submitting evidence of node misbehavior. - MethodEvidence = transaction.NewMethodName(ModuleName, "Evidence", Evidence{}) - - // MethodSubmitMsg is the method name for queuing incoming runtime messages. - MethodSubmitMsg = transaction.NewMethodName(ModuleName, "SubmitMsg", SubmitMsg{}) -) - // removed var block // Backend is a root hash implementation. diff --git a/coreapi/v22.2.11/staking/api/api.go b/coreapi/v22.2.11/staking/api/api.go index 89649716f..d609c6693 100644 --- a/coreapi/v22.2.11/staking/api/api.go +++ b/coreapi/v22.2.11/staking/api/api.go @@ -27,21 +27,6 @@ var ( CommonPoolAddress = original.CommonPoolAddress FeeAccumulatorAddress = original.FeeAccumulatorAddress GovernanceDepositsAddress = original.GovernanceDepositsAddress - - // MethodTransfer is the method name for transfers. - MethodTransfer = transaction.NewMethodName(ModuleName, "Transfer", Transfer{}) - // MethodBurn is the method name for burns. - MethodBurn = transaction.NewMethodName(ModuleName, "Burn", Burn{}) - // MethodAddEscrow is the method name for escrows. - MethodAddEscrow = transaction.NewMethodName(ModuleName, "AddEscrow", Escrow{}) - // MethodReclaimEscrow is the method name for escrow reclamations. - MethodReclaimEscrow = transaction.NewMethodName(ModuleName, "ReclaimEscrow", ReclaimEscrow{}) - // MethodAmendCommissionSchedule is the method name for amending commission schedules. - MethodAmendCommissionSchedule = transaction.NewMethodName(ModuleName, "AmendCommissionSchedule", AmendCommissionSchedule{}) - // MethodAllow is the method name for setting a beneficiary allowance. - MethodAllow = transaction.NewMethodName(ModuleName, "Allow", Allow{}) - // MethodWithdraw is the method name for - MethodWithdraw = transaction.NewMethodName(ModuleName, "Withdraw", Withdraw{}) ) var ( diff --git a/storage/oasis/nodeapi/cobalt/convert.go b/storage/oasis/nodeapi/cobalt/convert.go index 80a85d147..bd982476c 100644 --- a/storage/oasis/nodeapi/cobalt/convert.go +++ b/storage/oasis/nodeapi/cobalt/convert.go @@ -12,7 +12,6 @@ import ( coreCommon "github.com/oasisprotocol/oasis-core/go/common" consensus "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api" - "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api/transaction" genesis "github.com/oasisprotocol/nexus/coreapi/v22.2.11/genesis/api" governance "github.com/oasisprotocol/nexus/coreapi/v22.2.11/governance/api" registry "github.com/oasisprotocol/nexus/coreapi/v22.2.11/registry/api" @@ -25,7 +24,6 @@ import ( "github.com/oasisprotocol/nexus/storage/oasis/nodeapi" // data types for Cobalt gRPC APIs. - beaconCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/beacon/api" consensusCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/consensus/api" txResultsCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/consensus/api/transaction/results" genesisCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/genesis/api" @@ -37,15 +35,6 @@ import ( stakingCobalt "github.com/oasisprotocol/nexus/coreapi/v21.1.1/staking/api" ) -// We must register non-damask method types with the damask 'transaction' module. -var ( - // MethodPVSSCommit is the method name for a PVSS commitment. - MethodPVSSCommit = transaction.NewMethodName(beaconCobalt.ModuleName, "PVSSCommit", beaconCobalt.PVSSCommit{}) - - // MethodPVSSReveal is the method name for a PVSS reveal. - MethodPVSSReveal = transaction.NewMethodName(beaconCobalt.ModuleName, "PVSSReveal", beaconCobalt.PVSSReveal{}) -) - func convertProposal(p *governanceCobalt.Proposal) *governance.Proposal { results := make(map[governance.Vote]quantity.Quantity) for k, v := range p.Results { diff --git a/storage/oasis/nodeapi/eden/convert.go b/storage/oasis/nodeapi/eden/convert.go index b47442660..6a3efba8d 100644 --- a/storage/oasis/nodeapi/eden/convert.go +++ b/storage/oasis/nodeapi/eden/convert.go @@ -10,7 +10,6 @@ import ( coreCommon "github.com/oasisprotocol/oasis-core/go/common" "github.com/oasisprotocol/nexus/coreapi/v22.2.11/common/node" - "github.com/oasisprotocol/nexus/coreapi/v22.2.11/consensus/api/transaction" genesis "github.com/oasisprotocol/nexus/coreapi/v22.2.11/genesis/api" governance "github.com/oasisprotocol/nexus/coreapi/v22.2.11/governance/api" registry "github.com/oasisprotocol/nexus/coreapi/v22.2.11/registry/api" @@ -24,29 +23,15 @@ import ( // data types for Eden gRPC APIs. nodeEden "github.com/oasisprotocol/nexus/coreapi/v23.0/common/node" - consensusEden "github.com/oasisprotocol/nexus/coreapi/v23.0/consensus/api" txResultsEden "github.com/oasisprotocol/nexus/coreapi/v23.0/consensus/api/transaction/results" genesisEden "github.com/oasisprotocol/nexus/coreapi/v23.0/genesis/api" governanceEden "github.com/oasisprotocol/nexus/coreapi/v23.0/governance/api" - keymanagerEden "github.com/oasisprotocol/nexus/coreapi/v23.0/keymanager/api" registryEden "github.com/oasisprotocol/nexus/coreapi/v23.0/registry/api" roothashEden "github.com/oasisprotocol/nexus/coreapi/v23.0/roothash/api" schedulerEden "github.com/oasisprotocol/nexus/coreapi/v23.0/scheduler/api" stakingEden "github.com/oasisprotocol/nexus/coreapi/v23.0/staking/api" ) -// We must register non-damask method types with the damask 'transaction' module. -var ( - // MethodMeta is the method name for the special block metadata transaction. - MethodMeta = transaction.NewMethodName(consensusEden.ModuleName, "Meta", consensusEden.BlockMetadata{}) - - // MethodPublishMasterSecret is the method name for publishing master secret. - MethodPublishMasterSecret = transaction.NewMethodName(keymanagerEden.ModuleName, "PublishMasterSecret", keymanagerEden.SignedEncryptedMasterSecret{}) - - // MethodPublishEphemeralSecret is the method name for publishing ephemeral secret. - MethodPublishEphemeralSecret = transaction.NewMethodName(keymanagerEden.ModuleName, "PublishEphemeralSecret", keymanagerEden.SignedEncryptedEphemeralSecret{}) -) - func convertProposal(p *governanceEden.Proposal) *governance.Proposal { results := make(map[governance.Vote]quantity.Quantity) for k, v := range p.Results {