Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions api/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"api.audius.co/trashid"
"connectrpc.com/connect"
v1 "github.com/OpenAudio/go-openaudio/pkg/api/core/v1"
"github.com/OpenAudio/go-openaudio/pkg/sdk"
cconfig "github.com/OpenAudio/go-openaudio/pkg/core/config"
"github.com/OpenAudio/go-openaudio/pkg/core/server"
eth_gen "github.com/OpenAudio/go-openaudio/pkg/eth/contracts/gen"
Expand Down Expand Up @@ -259,37 +260,43 @@ func (app *ApiServer) relay(c *fiber.Ctx) error {
})
}

const sosEndpoint = "https://sos.audius.co"

func (app *ApiServer) handleRelay(ctx context.Context, logger *zap.Logger, decodedTx *v1.ManageEntityLegacy) (*v1.Transaction, error) {
allClients := app.openAudioPool.GetAll()
if len(allClients) == 0 {
logger.Error("no OpenAudio clients configured")
return nil, fmt.Errorf("no OpenAudio clients configured")
}

var lastErr error
for i, clientInfo := range allClients {
endpointLogger := logger.With(zap.String("openaudio_endpoint", clientInfo.Endpoint), zap.Int("attempt", i+1))
res, err := clientInfo.Client.Core.SendTransaction(ctx, connect.NewRequest(&v1.SendTransactionRequest{
Transaction: &v1.SignedTransaction{
Transaction: &v1.SignedTransaction_ManageEntity{
ManageEntity: decodedTx,
},
req := &v1.SendTransactionRequest{
Transaction: &v1.SignedTransaction{
Transaction: &v1.SignedTransaction_ManageEntity{
ManageEntity: decodedTx,
},
}))

if err != nil {
lastErr = err
endpointLogger.Warn("transaction failed, trying next", zap.Error(err))
continue
},
}

// mainnet
go func() {
allClients := app.openAudioPool.GetAll()
for i, clientInfo := range allClients {
endpointLogger := logger.With(zap.String("openaudio_endpoint", clientInfo.Endpoint), zap.Int("attempt", i+1))
res, err := clientInfo.Client.Core.SendTransaction(context.Background(), connect.NewRequest(req))
Comment on lines +275 to +279
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mainnet send is launched as a goroutine using context.Background() with no timeout. Under load, this can create unbounded concurrent goroutines and potentially hang indefinitely if an endpoint stalls (since it won't be canceled when the request ctx is canceled). Consider using a bounded context with timeout (e.g., context.WithTimeout) and/or a background worker/queue to control concurrency.

Copilot uses AI. Check for mistakes.
if err != nil {
endpointLogger.Warn("transaction failed, trying next", zap.Error(err))
continue
}
endpointLogger.Info("transaction confirmed", zap.String("hash", res.Msg.Transaction.GetHash()))
return
}
logger.Error("all mainnet endpoints failed")
}()

msg := res.Msg.Transaction
endpointLogger.Info("transaction confirmed", zap.String("hash", msg.GetHash()))
return msg, nil
// sos
sosClient := sdk.NewOpenAudioSDK(sosEndpoint)
sosLogger := logger.With(zap.String("openaudio_endpoint", sosEndpoint))
res, err := sosClient.Core.SendTransaction(ctx, connect.NewRequest(req))
if err != nil {
sosLogger.Warn("sos dual-write failed", zap.Error(err))
return nil, err
}
Comment on lines +293 to 297
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the SOS send the synchronous/authoritative call: failures from sosClient.Core.SendTransaction are returned to the API caller, and the receipt is built from the SOS transaction hash. The PR description says SOS should be best-effort/background in addition to the existing mainnet write; to keep existing semantics, the mainnet send should remain the one that determines the response, and the SOS dual-write should run asynchronously and not fail the request (log errors only).

Copilot uses AI. Check for mistakes.

logger.Error("all OpenAudio endpoints failed", zap.Error(lastErr))
return nil, fmt.Errorf("all endpoints failed, last error: %w", lastErr)
sosLogger.Info("sos dual-write confirmed", zap.String("hash", res.Msg.Transaction.GetHash()))
return res.Msg.Transaction, nil
}

func transactionToReceipt(tx *v1.Transaction, wallet string) map[string]interface{} {
Expand Down
Loading