Skip to content

Commit

Permalink
Merge pull request #472 from LF-Decentralized-Trust-labs/one-time-int…
Browse files Browse the repository at this point in the history
…ents

Ensure assemble always loads TX data locally, and on-chain enforcement of TXID uniqueness
  • Loading branch information
peterbroadhurst authored Dec 16, 2024
2 parents 4eae709 + 4a119e2 commit b812a05
Show file tree
Hide file tree
Showing 67 changed files with 1,669 additions and 1,655 deletions.
12 changes: 11 additions & 1 deletion config/pkg/pldconf/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ import (
)

type TxManagerConfig struct {
ABI ABIConfig `json:"abi"`
ABI ABIConfig `json:"abi"`
Transactions TransactionsConfig `json:"transactions"`
}

type ABIConfig struct {
Cache CacheConfig `json:"cache"`
}

type TransactionsConfig struct {
Cache CacheConfig `json:"cache"`
}

var TxManagerDefaults = &TxManagerConfig{
ABI: ABIConfig{
Cache: CacheConfig{
Capacity: confutil.P(100),
},
},
Transactions: TransactionsConfig{
Cache: CacheConfig{
Capacity: confutil.P(100),
},
},
}
2 changes: 1 addition & 1 deletion core/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/stretchr/testify v1.9.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.28.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/text v0.19.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
Expand Down Expand Up @@ -100,6 +99,7 @@ require (
gitlab.com/hfuss/mux-prometheus v0.0.5 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions core/go/internal/components/domainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ type DomainSmartContract interface {
Address() tktypes.EthAddress
ContractConfig() *prototk.ContractConfig

InitTransaction(ctx context.Context, tx *PrivateTransaction) error
AssembleTransaction(dCtx DomainContext, readTX *gorm.DB, tx *PrivateTransaction) error
InitTransaction(ctx context.Context, ptx *PrivateTransaction, localTx *ResolvedTransaction) error
AssembleTransaction(dCtx DomainContext, readTX *gorm.DB, ptx *PrivateTransaction, localTx *ResolvedTransaction) error
WritePotentialStates(dCtx DomainContext, readTX *gorm.DB, tx *PrivateTransaction) error
LockStates(dCtx DomainContext, readTX *gorm.DB, tx *PrivateTransaction) error
EndorseTransaction(dCtx DomainContext, readTX *gorm.DB, req *PrivateTransactionEndorseRequest) (*EndorsementResult, error)
PrepareTransaction(dCtx DomainContext, readTX *gorm.DB, tx *PrivateTransaction) error

InitCall(ctx context.Context, tx *TransactionInputs) ([]*prototk.ResolveVerifierRequest, error)
ExecCall(dCtx DomainContext, readTX *gorm.DB, tx *TransactionInputs, verifiers []*prototk.ResolvedVerifier) (*abi.ComponentValue, error)
InitCall(ctx context.Context, tx *ResolvedTransaction) ([]*prototk.ResolveVerifierRequest, error)
ExecCall(dCtx DomainContext, readTX *gorm.DB, tx *ResolvedTransaction, verifiers []*prototk.ResolvedVerifier) (*abi.ComponentValue, error)
}

type EndorsementResult struct {
Expand Down
2 changes: 1 addition & 1 deletion core/go/internal/components/privatetxmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type PrivateTxManager interface {
GetTxStatus(ctx context.Context, domainAddress string, txID uuid.UUID) (status PrivateTxStatus, err error)

// Synchronous function to call an existing deployed smart contract
CallPrivateSmartContract(ctx context.Context, call *TransactionInputs) (*abi.ComponentValue, error)
CallPrivateSmartContract(ctx context.Context, call *ResolvedTransaction) (*abi.ComponentValue, error)

//TODO this is just a placeholder until we figure out the external interface for events
// in the meantime, this is handy for some blackish box testing
Expand Down
21 changes: 8 additions & 13 deletions core/go/internal/components/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ import (
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
)

type TransactionInputs struct {
Domain string `json:"domain"`
From string `json:"from"`
To tktypes.EthAddress `json:"to"`
Function *abi.Entry `json:"function"`
Inputs tktypes.RawJSON `json:"inputs"`
Intent prototk.TransactionSpecification_Intent `json:"intent"`
PublicTxOptions pldapi.PublicTxOptions `json:"publicTxOptions"`
}

type TransactionStateRefs struct {
Confirmed []tktypes.HexBytes
Read []tktypes.HexBytes
Expand All @@ -54,6 +44,7 @@ type TransactionPreAssembly struct {
TransactionSpecification *prototk.TransactionSpecification `json:"transaction_specification"`
RequiredVerifiers []*prototk.ResolveVerifierRequest `json:"required_verifiers"`
Verifiers []*prototk.ResolvedVerifier `json:"verifiers"`
PublicTxOptions pldapi.PublicTxOptions `json:"public_tx_options"`
}

type FullState struct {
Expand Down Expand Up @@ -93,10 +84,14 @@ type TransactionPostAssembly struct {
// as it hops between the states in the state machine (on multiple paladin nodes) to reach
// a state that it can successfully (and anonymously) submitted it to the blockchain.
type PrivateTransaction struct {
ID uuid.UUID `json:"id"`

// INPUTS: Items that come in from the submitter of the transaction
Inputs *TransactionInputs `json:"inputs"`
// The identifier for the transaction
ID uuid.UUID `json:"id"`
Domain string `json:"domain"`
Address tktypes.EthAddress `json:"address"`

// This enum describes the point in the private transaction flow where processing of the transaction should stop
Intent prototk.TransactionSpecification_Intent `json:"intent"`

// ASSEMBLY PHASE: Items that get added to the transaction as it goes on its journey through
// assembly, signing and endorsement (possibly going back through the journey many times)
Expand Down
23 changes: 14 additions & 9 deletions core/go/internal/components/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ type TxCompletion struct {
PSC DomainSmartContract
}

type ResolvedTransaction struct {
Transaction *pldapi.Transaction `json:"transaction"`
DependsOn []uuid.UUID `json:"dependsOn"`
Function *ResolvedFunction `json:"function"`
}

// This is a transaction read for insertion into the Paladin database with all pre-verification completed.
type ValidatedTransaction struct {
ResolvedTransaction
LocalFrom string
Transaction *pldapi.Transaction
DependsOn []uuid.UUID
Function *ResolvedFunction
PublicTxData []byte
Inputs tktypes.RawJSON
}

// A resolved function on the ABI
type ResolvedFunction struct {
ABI abi.ABI
ABIReference *tktypes.Bytes32
Definition *abi.Entry
Signature string
// ABI abi.ABI `json:"abi"`
ABIReference *tktypes.Bytes32 `json:"abiReference"`
Definition *abi.Entry `json:"definition"`
Signature string `json:"signature"`
}

type TXManager interface {
Expand All @@ -85,11 +88,13 @@ type TXManager interface {
PrepareTransaction(ctx context.Context, tx *pldapi.TransactionInput) (*uuid.UUID, error)
PrepareTransactions(ctx context.Context, txs []*pldapi.TransactionInput) (txIDs []uuid.UUID, err error)
GetTransactionByID(ctx context.Context, id uuid.UUID) (*pldapi.Transaction, error)
GetResolvedTransactionByID(ctx context.Context, id uuid.UUID) (*ResolvedTransaction, error) // cache optimized
GetTransactionByIDFull(ctx context.Context, id uuid.UUID) (result *pldapi.TransactionFull, err error)
GetTransactionDependencies(ctx context.Context, id uuid.UUID) (*pldapi.TransactionDependencies, error)
GetPublicTransactionByNonce(ctx context.Context, from tktypes.EthAddress, nonce tktypes.HexUint64) (*pldapi.PublicTxWithBinding, error)
GetPublicTransactionByHash(ctx context.Context, hash tktypes.Bytes32) (*pldapi.PublicTxWithBinding, error)
QueryTransactions(ctx context.Context, jq *query.QueryJSON, dbTX *gorm.DB, pending bool) ([]*pldapi.Transaction, error)
QueryTransactionsResolved(ctx context.Context, jq *query.QueryJSON, dbTX *gorm.DB, pending bool) ([]*ResolvedTransaction, error)
QueryTransactionsFull(ctx context.Context, jq *query.QueryJSON, dbTX *gorm.DB, pending bool) (results []*pldapi.TransactionFull, err error)
QueryTransactionsFullTx(ctx context.Context, jq *query.QueryJSON, dbTX *gorm.DB, pending bool) ([]*pldapi.TransactionFull, error)
QueryTransactionReceipts(ctx context.Context, jq *query.QueryJSON) ([]*pldapi.TransactionReceipt, error)
Expand All @@ -102,6 +107,6 @@ type TXManager interface {
// These functions for use of the private TX manager for chaining private transactions.

PrepareInternalPrivateTransaction(ctx context.Context, dbTX *gorm.DB, tx *pldapi.TransactionInput, submitMode pldapi.SubmitMode) (func(), *ValidatedTransaction, error)
UpsertInternalPrivateTxsFinalizeIDs(ctx context.Context, dbTX *gorm.DB, txis []*ValidatedTransaction) error
UpsertInternalPrivateTxsFinalizeIDs(ctx context.Context, dbTX *gorm.DB, txis []*ValidatedTransaction) (postCommit func(), err error)
WritePreparedTransactions(ctx context.Context, dbTX *gorm.DB, prepared []*PrepareTransactionWithRefs) (postCommit func(), err error)
}
Loading

0 comments on commit b812a05

Please sign in to comment.