diff --git a/api/block_confirmation.go b/api/block_confirmation.go index 515c0ab6..e13d4f89 100644 --- a/api/block_confirmation.go +++ b/api/block_confirmation.go @@ -1,7 +1,6 @@ package api import ( - "api.audius.co/config" "github.com/gofiber/fiber/v2" "github.com/jackc/pgx/v5" ) @@ -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 diff --git a/api/health_check.go b/api/health_check.go index 3c1634e8..4131681f 100644 --- a/api/health_check.go +++ b/api/health_check.go @@ -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, diff --git a/api/relay.go b/api/relay.go index 3b0c030b..523c8dde 100644 --- a/api/relay.go +++ b/api/relay.go @@ -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" @@ -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()) @@ -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 diff --git a/api/server.go b/api/server.go index 1b4c6c81..195cc7d8 100644 --- a/api/server.go +++ b/api/server.go @@ -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, @@ -626,6 +627,7 @@ type BirdeyeClient interface { type ApiServer struct { *fiber.App + config *config.Config commsRpcProcessor *comms.RPCProcessor pool *dbv1.DBPools writePool *pgxpool.Pool @@ -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(), }) diff --git a/api/server_test.go b/api/server_test.go index 46d3e1f6..50922490 100644 --- a/api/server_test.go +++ b/api/server_test.go @@ -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", }) t.Cleanup(func() { diff --git a/api/v1_claim_rewards.go b/api/v1_claim_rewards.go index bf1bb7dd..f299195c 100644 --- a/api/v1_claim_rewards.go +++ b/api/v1_claim_rewards.go @@ -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, diff --git a/api/v1_coins_post_redeem.go b/api/v1_coins_post_redeem.go index b8d5a44a..29b3c026 100644 --- a/api/v1_coins_post_redeem.go +++ b/api/v1_coins_post_redeem.go @@ -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" @@ -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") } @@ -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 { @@ -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 } diff --git a/api/v1_create_coin.go b/api/v1_create_coin.go index 20ea7820..1b64e380 100644 --- a/api/v1_create_coin.go +++ b/api/v1_create_coin.go @@ -5,7 +5,6 @@ import ( "fmt" "time" - "api.audius.co/config" "api.audius.co/jobs" "github.com/gofiber/fiber/v2" "github.com/jackc/pgerrcode" @@ -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{ diff --git a/api/v1_create_reward_code.go b/api/v1_create_reward_code.go index b89379e4..3985fb8f 100644 --- a/api/v1_create_reward_code.go +++ b/api/v1_create_reward_code.go @@ -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" @@ -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()) } @@ -133,7 +132,7 @@ 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()) @@ -141,7 +140,7 @@ func (app *ApiServer) v1CreateRewardCode(c *fiber.Ctx) error { claimAuthority, claimAuthorityPrivateKey, err := utils.DeriveEthAddressForMint( []byte("claimAuthority"), - config.Cfg.LaunchpadDeterministicSecret, + app.config.LaunchpadDeterministicSecret, mintPubKey, ) if err != nil { @@ -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 diff --git a/api/v1_create_reward_code_test.go b/api/v1_create_reward_code_test.go index 90ff3b0d..a11bb09a 100644 --- a/api/v1_create_reward_code_test.go +++ b/api/v1_create_reward_code_test.go @@ -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" @@ -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) { @@ -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) @@ -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) @@ -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} timestamp := time.Now().UnixMilli() timestampStr := fmt.Sprintf("%d", timestamp) diff --git a/jobs/record_balance_history_test.go b/jobs/record_balance_history_test.go index 4ea16e25..4815e24d 100644 --- a/jobs/record_balance_history_test.go +++ b/jobs/record_balance_history_test.go @@ -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() @@ -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() @@ -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") defer pool.Close() ctx := context.Background() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/sql/02_test_template.sql b/sql/02_test_template.sql index 2dbdfcfc..26a0a2a3 100644 --- a/sql/02_test_template.sql +++ b/sql/02_test_template.sql @@ -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;