Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Apr 16, 2024
1 parent 9a865a0 commit c59009e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
35 changes: 6 additions & 29 deletions cmd/soroban-rpc/internal/methods/simulate_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"strings"
"sync/atomic"

"github.com/creachadair/jrpc2"
"github.com/stellar/go/support/log"
Expand Down Expand Up @@ -214,7 +213,7 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge
Error: err.Error(),
}
}
bucketListSize, err := getBucketListSize(ctx, ledgerReader, latestLedger)
bucketListSize, protocolVersion, err := getBucketListSizeAndProtocolVersion(ctx, ledgerReader, latestLedger)
if err != nil {
return SimulateTransactionResponse{
Error: err.Error(),
Expand All @@ -225,12 +224,6 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge
if request.ResourceConfig != nil {
resource_config = *request.ResourceConfig
}
protocolVersion, err := getProtocolVersion(ctx, daemon.CoreClient())
if err != nil {
return SimulateTransactionResponse{
Error: fmt.Sprintf("cannot obtain protocol version from core: %s", err),
}
}
params := preflight.PreflightGetterParameters{
LedgerEntryReadTx: readTx,
BucketListSize: bucketListSize,
Expand Down Expand Up @@ -293,33 +286,17 @@ func base64EncodeSlice(in [][]byte) []string {
return result
}

func getBucketListSize(ctx context.Context, ledgerReader db.LedgerReader, latestLedger uint32) (uint64, error) {
func getBucketListSizeAndProtocolVersion(ctx context.Context, ledgerReader db.LedgerReader, latestLedger uint32) (uint64, uint32, error) {
// obtain bucket size
var closeMeta, ok, err = ledgerReader.GetLedger(ctx, latestLedger)
if err != nil {
return 0, err
return 0, 0, err
}
if !ok {
return 0, fmt.Errorf("missing meta for latest ledger (%d)", latestLedger)
return 0, 0, fmt.Errorf("missing meta for latest ledger (%d)", latestLedger)
}
if closeMeta.V != 1 {
return 0, fmt.Errorf("latest ledger (%d) meta has unexpected verion (%d)", latestLedger, closeMeta.V)
}
return uint64(closeMeta.V1.TotalByteSizeOfBucketList), nil
}

var cachedCoreProtocolVersion atomic.Int32

// getProtocolVersion obtains the memoized protocol version from a core client
func getProtocolVersion(ctx context.Context, client interfaces.CoreClient) (int, error) {
version := cachedCoreProtocolVersion.Load()
if version != 0 {
return int(version), nil
}
info, err := client.Info(ctx)
if err != nil {
return 0, err
return 0, 0, fmt.Errorf("latest ledger (%d) meta has unexpected verion (%d)", latestLedger, closeMeta.V)
}
cachedCoreProtocolVersion.CompareAndSwap(0, int32(info.Info.ProtocolVersion))
return info.Info.ProtocolVersion, nil
return uint64(closeMeta.V1.TotalByteSizeOfBucketList), uint32(closeMeta.V1.LedgerHeader.Header.LedgerVersion), nil
}
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type PreflightGetterParameters struct {
OperationBody xdr.OperationBody
Footprint xdr.LedgerFootprint
ResourceConfig ResourceConfig
ProtocolVersion int
ProtocolVersion uint32
}

type PreflightParameters struct {
Expand All @@ -104,7 +104,7 @@ type PreflightParameters struct {
BucketListSize uint64
ResourceConfig ResourceConfig
EnableDebug bool
ProtocolVersion int
ProtocolVersion uint32
}

type XDRDiff struct {
Expand Down

0 comments on commit c59009e

Please sign in to comment.