Skip to content

Commit

Permalink
remove the legacy plugins, shorten the health checker interval. (#49)
Browse files Browse the repository at this point in the history
* remove the legacy plugins.

* refine, shorten the health checker interval, and update some comments.
  • Loading branch information
Jason-Zhangxin-Chen authored Feb 13, 2025
1 parent a93c2b8 commit 84e554b
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 435 deletions.
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ CONF_FILE = ./config/oracle_config.yml
E2E_TEST_DIR = ./e2e_test
E2E_TEST_PLUGIN_DIR = $(E2E_TEST_DIR)/plugins
E2E_TEST_TEMPLATE_PLUGIN_DIR = $(E2E_TEST_PLUGIN_DIR)/template_plugins
E2E_TEST_PRD_PLUGIN_DIR = $(E2E_TEST_PLUGIN_DIR)/production_plugins
E2E_TEST_SML_PLUGIN_DIR = $(E2E_TEST_PLUGIN_DIR)/simulator_plugins
E2E_TEST_OUTLIER_PLUGIN_DIR = $(E2E_TEST_PLUGIN_DIR)/outlier_plugins
E2E_TEST_MIX_PLUGIN_DIR = $(E2E_TEST_PLUGIN_DIR)/mix_plugins
Expand Down Expand Up @@ -44,7 +43,6 @@ mkdir:
mkdir -p $(SIMULATOR_BIN_DIR)
mkdir -p $(E2E_TEST_PLUGIN_DIR)
mkdir -p $(E2E_TEST_TEMPLATE_PLUGIN_DIR)
mkdir -p $(E2E_TEST_PRD_PLUGIN_DIR)
mkdir -p $(E2E_TEST_SML_PLUGIN_DIR)
mkdir -p $(E2E_TEST_MIX_PLUGIN_DIR)
mkdir -p $(E2E_TEST_FOREX_PLUGIN_DIR)
Expand Down Expand Up @@ -74,10 +72,6 @@ e2e-test-stuffs:
go build -o $(E2E_TEST_DIR)/simulator $(SIMULATOR_SRC_DIR)/main.go
chmod +x $(E2E_TEST_DIR)/simulator

# build binance plugin for e2e test.
go build -o $(E2E_TEST_PRD_PLUGIN_DIR)/binance $(PLUGIN_SRC_DIR)/binance/binance.go
chmod +x $(E2E_TEST_PRD_PLUGIN_DIR)/binance

# build amm plugin for e2e test.
go build -o $(E2E_TEST_CRYPTO_PLUGIN_DIR)/crypto_uniswap $(PLUGIN_SRC_DIR)/crypto_uniswap/uniswap_usdcx/crypto_uniswap_usdcx.go
chmod +x $(E2E_TEST_CRYPTO_PLUGIN_DIR)/*
Expand Down Expand Up @@ -120,13 +114,6 @@ amm-plugins:
go build -o $(PLUGIN_DIR)/crypto_uniswap $(PLUGIN_SRC_DIR)/crypto_uniswap/uniswap_usdcx/crypto_uniswap_usdcx.go
chmod +x $(PLUGIN_DIR)/*

# legacy piccadilly cax plugin, it sources order books from a CEX service built in python.
piccadilly-cax-plugin:
go build -o $(PLUGIN_DIR)/pcgc_cax $(PLUGIN_SRC_DIR)/pcgc_cax/
chmod +x $(PLUGIN_DIR)/pcgc_cax
# cp autonity round4 game PCGC CAX plugins for e2e testing
cp $(PLUGIN_DIR)/pcgc_cax $(E2E_TEST_CRYPTO_PLUGIN_DIR)/pcgc_cax

# build ATN-USDC, NTN-USDC, NTN-ATN data point simulator binary
crypto_source_simulator:
go build -o $(SIMULATOR_BIN_DIR)/simulator $(SIMULATOR_SRC_DIR)/main.go
Expand Down
54 changes: 0 additions & 54 deletions e2e_test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,6 @@ func TestAddCommitteeMember(t *testing.T) {
testNewValidatorJoinToCommittee(t, network, client, o, aut, endRound, pricePrecision)
}

func TestHappyCaseWithBinanceDataService(t *testing.T) {
var netConf = &NetworkConfig{
EnableL1Logs: false,
Symbols: []string{"BTC-USD", "BTC-USDC", "BTC-USDT", "BTC-USD4"},
VotePeriod: defaultVotePeriod,
PluginDIRs: []string{binancePlugDir, binancePlugDir, binancePlugDir, binancePlugDir},
}
network, err := createNetwork(netConf, numberOfValidators)
require.NoError(t, err)
defer network.Stop()

client, err := ethclient.Dial(fmt.Sprintf("ws://%s:%d", network.L1Nodes[0].Host, network.L1Nodes[0].WSPort))
require.NoError(t, err)
defer client.Close()

// bind client with oracle contract address
o, err := contract.NewOracle(types.OracleContractAddress, client)
require.NoError(t, err)

// first test happy case.
endRound := uint64(10)
testBinanceDataHappyCase(t, o, endRound)
}

func TestFeeRefund(t *testing.T) {
var netConf = &NetworkConfig{
EnableL1Logs: false,
Expand Down Expand Up @@ -821,36 +797,6 @@ func testRestartL1Node(t *testing.T, net *Network, index int, o *contract.Oracle
}
}

func testBinanceDataHappyCase(t *testing.T, o *contract.Oracle, beforeRound uint64) {
for {
time.Sleep(1 * time.Minute)
round, err := o.GetRound(nil)
require.NoError(t, err)

// continue to wait until end round.
if round.Uint64() < beforeRound {
continue
}

symbols, err := o.GetSymbols(nil)
require.NoError(t, err)

// as current round is not finalized yet, thus the round data of it haven't being aggregate,
// thus we will query the last round's data for the verification.
lastRound := new(big.Int).SetUint64(round.Uint64() - 1)

// get last round data for each symbol.
for _, s := range symbols {
d, err := o.GetRoundData(nil, lastRound, s)
require.NoError(t, err)
require.NotEqual(t, uint64(0), d.Price.Uint64())
require.Equal(t, true, d.Success)
}

break
}
}

func testAddNewSymbols(t *testing.T, network *Network, client *ethclient.Client, o *contract.Oracle, beforeRound uint64,
pricePrecision decimal.Decimal) {
chainID, err := client.ChainID(context.Background())
Expand Down
1 change: 0 additions & 1 deletion e2e_test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (
outlierPlugDir = "./plugins/outlier_plugins"
forexPlugDir = "./plugins/forex_plugins"
cryptoPlugDir = "./plugins/crypto_plugins"
binancePlugDir = "./plugins/production_plugins"
simulatorPlugDir = "./plugins/simulator_plugins"
mixPluginDir = "./plugins/mix_plugins"
defaultGenesis = "./autonity_l1_config/genesis_template.json"
Expand Down
14 changes: 8 additions & 6 deletions oracle_server/oracle_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ func (os *OracleServer) checkHealth() {
os.lostSync = false
return
}

os.logger.Debug("checking heart beat", "current round", os.curRound)
}

func (os *OracleServer) isVoter() (bool, error) {
Expand Down Expand Up @@ -917,6 +915,9 @@ func (os *OracleServer) Start() {
os.subPenalizedEvent.Unsubscribe()
}
case <-os.psTicker.C:
// shorten the health checker, if we have L1 connectivity issue, try to repair it before pre sampling starts.
os.checkHealth()

preSampleTS := time.Now().Unix()
err := os.handlePreSampling(preSampleTS)
if err != nil {
Expand Down Expand Up @@ -987,8 +988,8 @@ func (os *OracleServer) Start() {
os.logger.Info("handle new symbols", "new symbols", newSymbolEvent.Symbols, "activate at round", newSymbolEvent.Round)
os.handleNewSymbolsEvent(newSymbolEvent.Symbols)
case <-os.regularTicker.C:
os.checkHealth()
os.gcRoundData()
os.logger.Debug("round rotation", "current oracle round", os.curRound)
}
}
}
Expand Down Expand Up @@ -1145,7 +1146,8 @@ func ComputeConfidence(symbol string, numOfSamples, strategy int) uint8 {
return MaxConfidence
}

// Forex currencies with linear strategy.
// Forex currencies with "linear" strategy. Labeled "linear" but uses exponential scaling (1.75^n) since we
// are at the network bootstrapping phase with very limited number of data sources.
weight := BaseConfidence + SourceScalingFactor*uint64(math.Pow(1.75, float64(numOfSamples)))

if weight > MaxConfidence {
Expand All @@ -1155,9 +1157,9 @@ func ComputeConfidence(symbol string, numOfSamples, strategy int) uint8 {
return uint8(weight) //nolint
}

// by according to the spreading of price timestamp from the target timestamp,
// we reduce the confidence of the price, set the lowest confidence as 1.
func confidenceAdjustedPrice(historicRoundPrice *types.Price, target int64) (*types.Price, error) {
// by according to the spreading of price timestamp from the target timestamp,
// we reduce the confidence of the price, set the lowest confidence as 1.
// Calculate the time difference between the target timestamp and the historic price timestamp
timeDifference := target - historicRoundPrice.Timestamp

Expand Down
2 changes: 1 addition & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (tc *TemplateClient) FetchPrice(symbols []string) (common.Prices, error) {
return nil, err
}
tc.logger.Info("binance", "data", prices)
tc.logger.Info("template_plugin", "data", prices)
*/

// in this template, we just return fix values.
Expand Down
127 changes: 0 additions & 127 deletions plugins/binance/binance.go

This file was deleted.

23 changes: 0 additions & 23 deletions plugins/binance/binance_test.go

This file was deleted.

Loading

0 comments on commit 84e554b

Please sign in to comment.