Skip to content

Commit

Permalink
go/runtime/txpool: Limit outstanding transactions per sender
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Apr 14, 2022
1 parent 99f2529 commit b0c54d9
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 601 deletions.
1 change: 1 addition & 0 deletions .changelog/4665.feature.md
@@ -0,0 +1 @@
go/runtime/txpool: Limit outstanding transactions per sender
28 changes: 0 additions & 28 deletions go/runtime/host/helpers.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/errors"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
Expand Down Expand Up @@ -46,14 +45,6 @@ type RichRuntime interface {
method string,
args []byte,
) ([]byte, error)

// QueryBatchLimits requests the runtime to answer the batch limits query.
QueryBatchLimits(
ctx context.Context,
rb *block.Block,
lb *consensus.LightBlock,
epoch beacon.EpochTime,
) (map[transaction.Weight]uint64, error)
}

type richRuntime struct {
Expand Down Expand Up @@ -126,25 +117,6 @@ func (r *richRuntime) Query(
return resp.RuntimeQueryResponse.Data, nil
}

// Implements RichRuntime.
func (r *richRuntime) QueryBatchLimits(
ctx context.Context,
rb *block.Block,
lb *consensus.LightBlock,
epoch beacon.EpochTime,
) (map[transaction.Weight]uint64, error) {
resp, err := r.Query(ctx, rb, lb, epoch, 0, protocol.MethodQueryBatchWeightLimits, cbor.Marshal(nil))
if err != nil {
return nil, err
}

var weightLimits map[transaction.Weight]uint64
if err = cbor.Unmarshal(resp, &weightLimits); err != nil {
return nil, errors.WithContext(ErrInternal, fmt.Sprintf("malformed runtime response: %v", err))
}
return weightLimits, nil
}

// NewRichRuntime creates a new higher-level wrapper for a given runtime. It provides additional
// convenience functions for talking with a runtime.
func NewRichRuntime(rt Runtime) RichRuntime {
Expand Down
5 changes: 0 additions & 5 deletions go/runtime/host/mock/mock.go
Expand Up @@ -160,11 +160,6 @@ func (r *runtime) Call(ctx context.Context, body *protocol.Body) (*protocol.Body
rq := body.RuntimeQueryRequest

switch rq.Method {
// Handle Batch Weight Limits request.
case protocol.MethodQueryBatchWeightLimits:
return &protocol.Body{RuntimeQueryResponse: &protocol.RuntimeQueryResponse{
Data: cbor.Marshal(map[transaction.Weight]uint64{}),
}}, nil
default:
return &protocol.Body{RuntimeQueryResponse: &protocol.RuntimeQueryResponse{
Data: cbor.Marshal(rq.Method + " world at:" + fmt.Sprintf("%d", rq.ConsensusBlock.Height)),
Expand Down
23 changes: 16 additions & 7 deletions go/runtime/host/protocol/types.go
Expand Up @@ -6,6 +6,7 @@ import (

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/common"
"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"
"github.com/oasisprotocol/oasis-core/go/common/errors"
Expand All @@ -20,9 +21,6 @@ import (
storage "github.com/oasisprotocol/oasis-core/go/storage/api"
)

// MethodQueryBatchWeightLimits is the name of the runtime batch weight limits query method.
const MethodQueryBatchWeightLimits = "internal.BatchWeightLimits"

// NOTE: Bump RuntimeProtocol version in go/common/version if you
// change any of the structures below.

Expand Down Expand Up @@ -258,8 +256,15 @@ type CheckTxMetadata struct {
// Priority is the transaction's priority.
Priority uint64 `json:"priority,omitempty"`

// Weight are runtime specific transaction weights.
Weights map[transaction.Weight]uint64 `json:"weights,omitempty"`
// Sender is the unique identifier of the transaction sender.
Sender []byte `json:"sender,omitempty"`
// SenderSeq is the per-sender sequence number of the transaction.
SenderSeq uint64 `json:"sender_seq,omitempty"`

// Fields below are deprecated to avoid breaking protocol changes. They may be removed once
// all runtimes stop sending those fields.

Deprecated1 cbor.RawMessage `json:"weights,omitempty"`
}

// IsSuccess returns true if transaction execution was successful.
Expand Down Expand Up @@ -340,8 +345,7 @@ type RuntimeExecuteTxBatchRequest struct {

// RuntimeExecuteTxBatchResponse is a worker execute tx batch response message body.
type RuntimeExecuteTxBatchResponse struct {
Batch ComputedBatch `json:"batch"`
BatchWeightLimits map[transaction.Weight]uint64 `json:"batch_weight_limits"`
Batch ComputedBatch `json:"batch"`

// TxHashes are the transaction hashes of the included batch.
TxHashes []hash.Hash `json:"tx_hashes,omitempty"`
Expand All @@ -352,6 +356,11 @@ type RuntimeExecuteTxBatchResponse struct {
TxInputRoot hash.Hash `json:"tx_input_root,omitempty"`
// TxInputWriteLog is the write log for generating transaction inputs.
TxInputWriteLog storage.WriteLog `json:"tx_input_write_log,omitempty"`

// Fields below are deprecated to avoid breaking protocol changes. They may be removed once
// all runtimes stop sending those fields.

Deprecated1 cbor.RawMessage `json:"batch_weight_limits,omitempty"`
}

// RuntimeKeyManagerPolicyUpdateRequest is a runtime key manager policy request
Expand Down
22 changes: 0 additions & 22 deletions go/runtime/transaction/transaction.go
Expand Up @@ -149,28 +149,6 @@ type outputArtifacts struct {
Output []byte
}

// Weight is the transaction weight type.
type Weight string

const (
// WeightConsensusMessages is the consensus messages weight key.
WeightConsensusMessages = Weight("consensus_messages")
// WeightSizeBytes is the transaction byte size weight key.
WeightSizeBytes = Weight("size_bytes")
// WeightCount is the transaction count weight key.
WeightCount = Weight("count")
)

// IsCustom returns if the weight is a custom runtime weight.
func (w Weight) IsCustom() bool {
switch w {
case WeightConsensusMessages, WeightSizeBytes, WeightCount:
return false
default:
return true
}
}

// Transaction is an executed (or executing) transaction.
//
// This is the transaction representation used for convenience as a collection
Expand Down
202 changes: 0 additions & 202 deletions go/runtime/txpool/priority_queue.go

This file was deleted.

0 comments on commit b0c54d9

Please sign in to comment.