Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions api/block_confirmation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"api.audius.co/config"
"github.com/gofiber/fiber/v2"
"github.com/jackc/pgx/v5"
)
Expand Down Expand Up @@ -39,7 +38,7 @@ func (app *ApiServer) BlockConfirmation(c *fiber.Ctx) error {
rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{
"blockHash": params.BlockHash,
"blockNumber": params.BlockNumber,
"chainId": config.Cfg.ChainId,
"chainId": app.config.ChainId,
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion api/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (app *ApiServer) healthCheck(c *fiber.Ctx) error {
contentNodes := make([]contentNode, 0, len(healthyNodes))
for _, node := range healthyNodes {
// icky reaching into config to check upload nodes
if slices.Contains(app.contentNodeMonitor.config.UploadNodes, node.Endpoint) {
if slices.Contains(app.config.UploadNodes, node.Endpoint) {
contentNodes = append(contentNodes, contentNode{
DelegateOwnerWallet: node.DelegateOwnerWallet,
Endpoint: node.Endpoint,
Expand Down
7 changes: 3 additions & 4 deletions api/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"

"api.audius.co/api/dbv1"
"api.audius.co/config"
"api.audius.co/trashid"
"connectrpc.com/connect"
v1 "github.com/OpenAudio/go-openaudio/pkg/api/core/v1"
Expand Down Expand Up @@ -176,8 +175,8 @@ func (app *ApiServer) relay(c *fiber.Ctx) error {
logger.Info("decoded transaction", zap.Any("encodedABI", request.EncodedABI))

wallet, _, err := server.RecoverPubkeyFromCoreTx(&cconfig.Config{
AcdcChainID: config.Cfg.AudiusdChainID,
AcdcEntityManagerAddress: config.Cfg.AudiusdEntityManagerAddress,
AcdcChainID: app.config.AudiusdChainID,
AcdcEntityManagerAddress: app.config.AudiusdEntityManagerAddress,
}, decodedTx)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "bad request: "+err.Error())
Expand All @@ -193,7 +192,7 @@ func (app *ApiServer) relay(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusForbidden, "forbidden: signer does not match sender")
}

isVerifier := strings.EqualFold(wallet, config.Cfg.VerifierAddress)
isVerifier := strings.EqualFold(wallet, app.config.VerifierAddress)
_, anonymouslyAllowed := anonymouslyAllowedActions[operation]

// skip auth check if verifier or operation is anonymously allowed
Expand Down
6 changes: 4 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func NewApiServer(config config.Config) *ApiServer {
ReadBufferSize: 32_768,
UnescapePath: true,
}),
config: &config,
commsRpcProcessor: commsRpcProcessor,
env: config.Env,
audiusAppUrl: config.AudiusAppUrl,
Expand Down Expand Up @@ -626,6 +627,7 @@ type BirdeyeClient interface {

type ApiServer struct {
*fiber.App
config *config.Config
commsRpcProcessor *comms.RPCProcessor
pool *dbv1.DBPools
writePool *pgxpool.Pool
Expand Down Expand Up @@ -658,8 +660,8 @@ type ApiServer struct {

func (app *ApiServer) home(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"env": config.Cfg.Env,
"git": config.Cfg.Git,
"env": app.config.Env,
"git": app.config.Git,
"started": app.started,
"uptime": time.Since(app.started).Truncate(time.Second).String(),
})
Expand Down
1 change: 1 addition & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func emptyTestApp(t *testing.T) *ApiServer {
// Disable message push by default. Tests for it can create
// an RPC processor directly.
CommsMessagePush: false,
ChainId: "audius-devnet",
Copy link
Member

Choose a reason for hiding this comment

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

what's this change from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we depend on this being devnet for the block_confirmation tests. I didn't realize we had a whole separate config we started here for tests :P

})

t.Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion api/v1_claim_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error {
UserBank: *bankAccount,
}

validators := app.validators.GetNodes()
validators := app.config.ArtistCoinRewardsStaticSenders
sigs, err := claimReward(
ctx,
rewardClaim,
Expand Down
7 changes: 3 additions & 4 deletions api/v1_coins_post_redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"strings"

"api.audius.co/config"
"api.audius.co/solana/spl"
"api.audius.co/solana/spl/programs/reward_manager"
"api.audius.co/utils"
Expand All @@ -31,7 +30,7 @@ type CoinRewardParams struct {

func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
// #region Validate Params
if config.Cfg.LaunchpadDeterministicSecret == "" {
if app.config.LaunchpadDeterministicSecret == "" {
return fiber.NewError(fiber.StatusInternalServerError, "Claim authority base is not configured")
}

Expand Down Expand Up @@ -62,7 +61,7 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {
// Derive claim authority key for mint
claimAuthorityPublicKey, claimAuthorityPrivKeyString, err := utils.DeriveEthAddressForMint(
[]byte("claimAuthority"),
config.Cfg.LaunchpadDeterministicSecret,
app.config.LaunchpadDeterministicSecret,
mint,
)
if err != nil {
Expand Down Expand Up @@ -308,7 +307,7 @@ func (app *ApiServer) v1CoinsPostRedeem(c *fiber.Ctx) error {

neededAttestations := (minVotes + 1) - len(attestationsData.Messages)

for _, validator := range config.Cfg.ArtistCoinRewardsStaticSenders {
for _, validator := range app.config.ArtistCoinRewardsStaticSenders {
if len(attestations) >= neededAttestations {
break
}
Expand Down
3 changes: 1 addition & 2 deletions api/v1_create_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

"api.audius.co/config"
"api.audius.co/jobs"
"github.com/gofiber/fiber/v2"
"github.com/jackc/pgerrcode"
Expand Down Expand Up @@ -157,7 +156,7 @@ func (app *ApiServer) v1CreateCoin(c *fiber.Ctx) error {
}

// Update the pool for the new coin
coinJob := jobs.NewCoinDBCJob(config.Cfg, app.writePool)
coinJob := jobs.NewCoinDBCJob(*app.config, app.writePool)
coinJob.UpdatePoolForBaseMint(c.Context(), result.Mint, true)

return c.Status(fiber.StatusCreated).JSON(fiber.Map{
Expand Down
9 changes: 4 additions & 5 deletions api/v1_create_reward_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/big"
"time"

"api.audius.co/config"
"api.audius.co/utils"
"connectrpc.com/connect"
v1 "github.com/OpenAudio/go-openaudio/pkg/api/core/v1"
Expand Down Expand Up @@ -119,7 +118,7 @@ func (app *ApiServer) v1CreateRewardCode(c *fiber.Ctx) error {
}
}

_, err := verifySignatureAgainstKeys(req.Signature, message, config.Cfg.RewardCodeAuthorizedKeys)
_, err := verifySignatureAgainstKeys(req.Signature, message, app.config.RewardCodeAuthorizedKeys)
if err != nil {
return fiber.NewError(fiber.StatusForbidden, "Unauthorized: "+err.Error())
}
Expand All @@ -133,15 +132,15 @@ func (app *ApiServer) v1CreateRewardCode(c *fiber.Ctx) error {
var rewardAddress string

// Only create reward pool if deterministic secret is configured
if config.Cfg.LaunchpadDeterministicSecret != "" {
if app.config.LaunchpadDeterministicSecret != "" {
mintPubKey, err := solana.PublicKeyFromBase58(req.Mint)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Invalid mint address: "+err.Error())
}

claimAuthority, claimAuthorityPrivateKey, err := utils.DeriveEthAddressForMint(
[]byte("claimAuthority"),
config.Cfg.LaunchpadDeterministicSecret,
app.config.LaunchpadDeterministicSecret,
mintPubKey,
)
if err != nil {
Expand All @@ -155,7 +154,7 @@ func (app *ApiServer) v1CreateRewardCode(c *fiber.Ctx) error {
}

// Create OpenAudio SDK instance and set the private key
oap := sdk.NewOpenAudioSDK(config.Cfg.AudiusdURL)
oap := sdk.NewOpenAudioSDK(app.config.AudiusdURL)
oap.SetPrivKey(privateKey)

// Get current chain status to calculate deadline
Expand Down
11 changes: 5 additions & 6 deletions api/v1_create_reward_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"
"time"

"api.audius.co/config"
"api.audius.co/database"
"github.com/gagliardetto/solana-go"
"github.com/mr-tron/base58"
Expand Down Expand Up @@ -41,9 +40,9 @@ func TestV1CreateRewardCode(t *testing.T) {
database.Seed(app.pool.Replicas[0], fixtures)

// Save original config and restore after tests
originalKeys := config.Cfg.RewardCodeAuthorizedKeys
originalKeys := app.config.RewardCodeAuthorizedKeys
defer func() {
config.Cfg.RewardCodeAuthorizedKeys = originalKeys
app.config.RewardCodeAuthorizedKeys = originalKeys
}()

t.Run("Unauthorized with invalid signature", func(t *testing.T) {
Expand Down Expand Up @@ -112,7 +111,7 @@ func TestV1CreateRewardCode(t *testing.T) {
// Convert to Solana format and inject into config
solanaPubKey := solana.PublicKeyFromBytes(testPublicKey)
testPubKeyBase58 := solanaPubKey.String()
config.Cfg.RewardCodeAuthorizedKeys = []string{testPubKeyBase58}
app.config.RewardCodeAuthorizedKeys = []string{testPubKeyBase58}

timestamp := time.Now().UnixMilli()
timestampStr := fmt.Sprintf("%d", timestamp)
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestV1CreateRewardCode(t *testing.T) {
solanaPubKey2 := solana.PublicKeyFromBytes(testPublicKey2)
testPubKeyBase58 := solanaPubKey.String()
testPubKeyBase582 := solanaPubKey2.String()
config.Cfg.RewardCodeAuthorizedKeys = []string{testPubKeyBase58, testPubKeyBase582}
app.config.RewardCodeAuthorizedKeys = []string{testPubKeyBase58, testPubKeyBase582}

timestamp := time.Now().UnixMilli()
timestampStr := fmt.Sprintf("%d", timestamp)
Expand Down Expand Up @@ -212,7 +211,7 @@ func TestV1CreateRewardCode(t *testing.T) {
// Convert to Solana format and inject into config
solanaPubKey := solana.PublicKeyFromBytes(testPublicKey)
testPubKeyBase58 := solanaPubKey.String()
config.Cfg.RewardCodeAuthorizedKeys = []string{testPubKeyBase58}
app.config.RewardCodeAuthorizedKeys = []string{testPubKeyBase58}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should really just stick these into the test config, but leaving as-is for now


timestamp := time.Now().UnixMilli()
timestampStr := fmt.Sprintf("%d", timestamp)
Expand Down
22 changes: 11 additions & 11 deletions jobs/record_balance_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newTestConfig() config.Config {
}

func TestRecordBalanceHistory(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestRecordBalanceHistory(t *testing.T) {
}

func TestRecordBalanceHistoryTimestampTruncation(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestRecordBalanceHistoryTimestampTruncation(t *testing.T) {
}

func TestRecordBalanceHistoryConflictHandling(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
Copy link
Contributor Author

@rickyrombo rickyrombo Dec 2, 2025

Choose a reason for hiding this comment

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

fyi @dylanjeffers sorry I didn't catch this in initial review - each "package" of tests in go runs in parallel, and only one database can be created from a template at a time, so each package has its own template to use for tests to avoid race conditions

super annoying footgun but it makes tests faasstt

defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestRecordBalanceHistoryConflictHandling(t *testing.T) {
}

func TestRecordBalanceHistoryZeroBalance(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestRecordBalanceHistoryZeroBalance(t *testing.T) {
}

func TestRecordBalanceHistoryNullPrice(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestRecordBalanceHistoryNullPrice(t *testing.T) {
}

func TestRecordUserBalanceHistory(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestRecordUserBalanceHistory(t *testing.T) {
}

func TestRecordBalanceHistoryMultipleMints(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestRecordBalanceHistoryMultipleMints(t *testing.T) {
}

func TestRecordBalanceHistoryConcurrentRuns(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestRecordBalanceHistoryConcurrentRuns(t *testing.T) {
}

func TestRecordBalanceHistoryNoUsers(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand All @@ -487,7 +487,7 @@ func TestRecordBalanceHistoryNoUsers(t *testing.T) {
}

func TestRecordBalanceHistoryDecimalPrecision(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down Expand Up @@ -553,7 +553,7 @@ func TestRecordBalanceHistoryDecimalPrecision(t *testing.T) {
}

func TestRecordBalanceHistoryOnlyTrackedCoins(t *testing.T) {
pool := database.CreateTestDatabase(t, "test_api")
pool := database.CreateTestDatabase(t, "test_jobs")
defer pool.Close()

ctx := context.Background()
Expand Down
1 change: 1 addition & 0 deletions sql/02_test_template.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE DATABASE test_api TEMPLATE postgres;
CREATE DATABASE test_jobs TEMPLATE postgres;
CREATE DATABASE test_comms TEMPLATE postgres;
CREATE DATABASE test_database TEMPLATE postgres;
CREATE DATABASE test_hll TEMPLATE postgres;
Expand Down