Skip to content

Commit

Permalink
return feederaddress on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Oct 4, 2023
1 parent 8f5b5cd commit 1ba8c9c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cmd/http/oraclebuilder/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (ob *Env) Create(context *gin.Context) {
address = keypair.GetPublickey()

if !isUpdate {
err = ob.PodHelper.CreateOracleFeeder(context, feederID, creator, oracleaddress, address, chainID, symbols, feedSelection, blockchainnode, frequency, sleepSeconds, deviationPermille, mandatoryFrequency)
err = ob.PodHelper.CreateOracleFeeder(context, feederID, creator, address, oracleaddress, chainID, symbols, feedSelection, blockchainnode, frequency, sleepSeconds, deviationPermille, mandatoryFrequency)
if err != nil {
log.Errorln("error CreateOracleFeeder ", err)
context.JSON(http.StatusInternalServerError, errors.New("error creating oraclefeeder"))
Expand Down
4 changes: 3 additions & 1 deletion cmd/http/oraclebuilder/oraclebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func main() {
signerurl := utils.Getenv("SIGNER_URL", "signer.dia-oracle-feeder:50052")
diaRestURL := utils.Getenv("DIA_REST_URL", "https://api.diadata.org")
diaGraphqlURL := utils.Getenv("DIA_GRAPHQL_URL", "https://api.diadata.org/graphql/query")
postgresqlHost := utils.Getenv("DIA_GRAPHQL_URL", "dia-postgresql.dia-db")

rateLimitOracleCreationString := utils.Getenv("RATE_LIMIT_ORACLE_CREATION", "4")
rateLimitOracleCreation, _ := strconv.ParseInt(rateLimitOracleCreationString, 10, 64)

Expand All @@ -48,7 +50,7 @@ func main() {
AllowedBackends: []keyring.BackendType{keyring.K8Secret},
})

oracle := NewEnv(relStore, ph, ring, int(rateLimitOracleCreation))
oracle := NewEnv(relStore, ph, ring, int(rateLimitOracleCreation), postgresqlHost)

r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
Expand Down
9 changes: 5 additions & 4 deletions cmd/http/oraclebuilder/utils/podhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ type PodHelper struct {
SignerURL string
DiaRestURL string
DiaGraphqlURL string
PostgresHost string
}

// NewPodHelper creates a new instance of PodHelper.
func NewPodHelper(image, namespace, affinity, signerURL, diaRestURL, diaGraphqlURL string) *PodHelper {
func NewPodHelper(image, namespace, affinity, signerURL, diaRestURL, diaGraphqlURL, postgresHost string) *PodHelper {
config, err := rest.InClusterConfig()
if err != nil {
// try using kube config
Expand All @@ -57,11 +58,11 @@ func NewPodHelper(image, namespace, affinity, signerURL, diaRestURL, diaGraphqlU
if err != nil {
log.Fatal(err)
}
return &PodHelper{k8sclient: client, Image: image, NameSpace: namespace, Affinity: affinity, SignerURL: signerURL, DiaRestURL: diaRestURL, DiaGraphqlURL: diaGraphqlURL}
return &PodHelper{k8sclient: client, Image: image, NameSpace: namespace, Affinity: affinity, SignerURL: signerURL, DiaRestURL: diaRestURL, DiaGraphqlURL: diaGraphqlURL, PostgresHost: postgresHost}
}

// CreateOracleFeeder creates a new Oracle Feeder Pod in Kubernetes.
func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, creator, feederAddress string, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error {
func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID, creator, feederAddress, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error {

envvars := kh.PodEnvironmentVariables(feederID, creator, oracle, chainID, symbols, feedSelection, blockchainnode, frequency, sleepSeconds, deviationPermille, mandatoryFrequency)

Expand Down Expand Up @@ -148,7 +149,7 @@ func (kh *PodHelper) PodEnvironmentVariables(feederID string, owner string, orac
vars = append(vars, diaRestAPIenv, diaGraphqlenv, publickeyenv, deployedcontractenv, chainidenv, signerservice, sleepsecondenv, deviationenv, frequencyseconds, oracletype, oraclesymbols, oraclefeederid, blockchainnodeenv, mandatoryfrequencyenv, feedSelectionenv)

// ---
postgreshost := corev1.EnvVar{Name: "POSTGRES_HOST", Value: "dia-postgresql.dia-db"}
postgreshost := corev1.EnvVar{Name: "POSTGRES_HOST", Value: kh.PostgresHost}
postgresuser := corev1.EnvVar{Name: "POSTGRES_USER", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "user", LocalObjectReference: corev1.LocalObjectReference{Name: "user.graphqlserver"}}}}
postgrespassword := corev1.EnvVar{Name: "POSTGRES_PASSWORD", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "password", LocalObjectReference: corev1.LocalObjectReference{Name: "user.graphqlserver"}}}}
postgresdb := corev1.EnvVar{Name: "POSTGRES_DB", Value: "postgres"}
Expand Down
57 changes: 41 additions & 16 deletions deployments/config/pginit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,57 @@ CREATE TABLE nftexchange (
UNIQUE (name)
);


CREATE TABLE oracleconfig (
id UUID DEFAULT gen_random_uuid(),
id uuid DEFAULT gen_random_uuid(),
address text NOT NULL,
feeder_id text NOT NULL,
owner text NOT NULL,
symbols text NOT NULL,
feeder_address text NOT NULL,
chainID text NOT NULL,
active boolean default true,
deleted boolean default false,
frequency text ,
chainid text NOT NULL,
active boolean DEFAULT true,
frequency text,
sleepseconds text,
deviationpermille text,
blockchainnode text,
blockchainnode text DEFAULT ''::text,
feeder_address text,
mandatory_frequency text,
createddate TIMESTAMP NOT NULL DEFAULT NOW(),
lastupdate TIMESTAMP NOT NULL,
UNIQUE (id),
UNIQUE (feeder_id)
deleted boolean DEFAULT false,
createddate timestamp without time zone DEFAULT now() NOT NULL,
lastupdate timestamp without time zone,
creation_block bigint,
creation_block_time timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone,
feedselection text,
expired boolean DEFAULT false,
expired_time timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone
);

ALTER TABLE oracleconfig ADD COLUMN creation_block_time TIMESTAMP DEFAULT 'epoch'::timestamp;
ALTER TABLE oracleconfig ADD COLUMN feedSelection TEXT ;
ALTER TABLE oracleconfig ADD COLUMN expired boolean default false ;
ALTER TABLE oracleconfig ADD COLUMN expired_time TIMESTAMP DEFAULT 'epoch'::timestamp;


-- CREATE TABLE oracleconfig (
-- id UUID DEFAULT gen_random_uuid(),
-- address text NOT NULL,
-- feeder_id text NOT NULL,
-- owner text NOT NULL,
-- symbols text NOT NULL,
-- feeder_address text NOT NULL,
-- chainID text NOT NULL,
-- active boolean default true,
-- deleted boolean default false,
-- frequency text ,
-- sleepseconds text,
-- deviationpermille text,
-- blockchainnode text,
-- mandatory_frequency text,
-- createddate TIMESTAMP NOT NULL DEFAULT NOW(),
-- lastupdate TIMESTAMP NOT NULL,
-- UNIQUE (id),
-- UNIQUE (feeder_id)
-- );

-- ALTER TABLE oracleconfig ADD COLUMN creation_block_time TIMESTAMP DEFAULT 'epoch'::timestamp;
-- ALTER TABLE oracleconfig ADD COLUMN feedSelection TEXT ;
-- ALTER TABLE oracleconfig ADD COLUMN expired boolean default false ;
-- ALTER TABLE oracleconfig ADD COLUMN expired_time TIMESTAMP DEFAULT 'epoch'::timestamp;



Expand Down
4 changes: 2 additions & 2 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ func (rdb *RelDB) GetOracleConfig(address, chainid string) (oracleconfig dia.Ora
feedSelection sql.NullString
)
query := fmt.Sprintf(`
SELECT address, feeder_id, owner,symbols, chainid, feedSelection,deviationpermille, sleepseconds,frequency, blockchainnode, mandatory_frequency
SELECT address, feeder_id, owner,feeder_address,symbols, chainid, feedSelection,deviationpermille, sleepseconds,frequency, blockchainnode, mandatory_frequency
FROM %s
WHERE address=$1 and chainid=$2`, oracleconfigTable)
fmt.Println(query)
err = rdb.postgresClient.QueryRow(context.Background(), query, address, chainid).Scan(&oracleconfig.Address, &oracleconfig.FeederID, &oracleconfig.Owner, &symbols, &oracleconfig.ChainID, &feedSelection, &oracleconfig.DeviationPermille, &oracleconfig.SleepSeconds, &oracleconfig.Frequency, &oracleconfig.BlockchainNode, &oracleconfig.MandatoryFrequency)
err = rdb.postgresClient.QueryRow(context.Background(), query, address, chainid).Scan(&oracleconfig.Address, &oracleconfig.FeederID, &oracleconfig.Owner, &oracleconfig.FeederAddress, &symbols, &oracleconfig.ChainID, &feedSelection, &oracleconfig.DeviationPermille, &oracleconfig.SleepSeconds, &oracleconfig.Frequency, &oracleconfig.BlockchainNode, &oracleconfig.MandatoryFrequency)
if err != nil {
return
}
Expand Down

0 comments on commit 1ba8c9c

Please sign in to comment.