Skip to content

Commit e4d9fa7

Browse files
authored
Merge pull request #227 from filecoin-project/feature/backend
feat: backend code upgrade
2 parents e46ce17 + 122e597 commit e4d9fa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1057
-968
lines changed

backend/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ MYSQL_PASSWORD= # Password for the MySQL database
99
MYSQL_DATABASE= # Database name for the MySQL database
1010

1111
POWERVOTING_CONTRACT= # Contract address for the PowerVoting contract
12-
ORACLE_POWERS_CONTRACT= # Contract address for the Oracle Powers contract
1312
SYNC_EVENT_START_HEIGHT= # Start height for the sync event
1413
ORACLE_CONTRACT= # Contract address for the Oracle contract
1514
FIP_CONTRACT= # Contract address for the FIP contract
@@ -18,9 +17,10 @@ FIP_INIT_EDITOR= # Address of the FIP init editor on deploy the FIP Cont
1817
POWERVOTING_API_PATH= # API path for the PowerVoting contract
1918
ORACLE_API_PATH= # API path for the Oracle contract
2019
FIP_ABI_PATH= # ABI path for the FIP contract
21-
ORACLE_POWERS_ABI_PATH= # ABI path for the Oracle Powers contract
20+
2221

2322
MINER_ID_PREFIX=t0 # Miner ID prefix for the network
2423
CHAIN_ID=314159 # Chain ID for the network
2524
CHAIN_NAME=FileCoin-Calibration # Chain name for the network
2625
CHAIN_RPC_NODE=http://192.168.11.139:1235/rpc/v1 # RPC URL for the chain node
26+
GITHUB_TOKEN=github_pat_XXXXXX,github_pat_XXXXXX # https://github.com/settings/tokens

backend/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ FROM alpine:latest
2020
WORKDIR /dist
2121

2222
COPY --from=backend-builder /build/app .
23-
COPY --from=backend-builder /build/configuration.yaml .
23+
COPY --from=backend-builder /build/configuration-backend.yaml .
24+
2425
COPY --from=backend-builder /build/abi/power-voting.json ./
25-
COPY --from=backend-builder /build/abi/oracle.json ./
2626
COPY --from=backend-builder /build/abi/power-voting-fip.json ./
27+
# Copy oracle abi to instance
2728
COPY --from=backend-builder /build/abi/oracle-powers.json ./
28-
29-
30-
EXPOSE 18007
31-
29+
COPY --from=backend-builder /build/abi/oracle.json ./
30+
COPY --from=backend-builder /build/.env ./
3231
CMD ["/dist/app"]

backend/api/power.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ func GetAddressPower(c *constant.Context) {
3232
return
3333
}
3434

35+
ethAddr, err := req.AddressReq.ToEthAddr()
36+
if err != nil {
37+
zap.L().Error("GetAddressPower invalid address: ", zap.String("address", req.AddressReq.Address), zap.Error(err))
38+
Error(c.Context, err)
39+
return
40+
}
41+
3542
// Call the client's GetAddressPowerByDay method to retrieve power information.
36-
power, err := snapshot.GetAddressPowerByDay(req.ChainId, req.Address, req.PowerDay)
43+
power, err := snapshot.GetAddressPowerByDay(req.ChainId, ethAddr, req.PowerDay)
3744
if err != nil {
3845
zap.L().Error(
3946
"get snapshot power error ",
40-
zap.String("address", req.Address),
47+
zap.String("address", ethAddr),
4148
zap.String("power day", req.PowerDay),
4249
zap.Int64("chain id", req.ChainId),
4350
zap.Error(err),

backend/api/rpc/backend.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ message GetAllVoterAddressResponse {
2424
}
2525

2626
message GetVoterInfoResponse {
27-
repeated string miner_ids = 1;
28-
string actor_id =2;
29-
string github_account = 3;
27+
string actor_id = 1;
28+
string github_account = 2;
29+
repeated string miner_ids = 3;
3030
}

backend/api/rpc/client_test.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

backend/api/rpc/proto/backend.pb.go

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/api/rpc/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (b *BackendRpc) GetVoterInfo(ctx context.Context, req *pb.GetVoterInfoReque
4141
return &pb.GetVoterInfoResponse{
4242
MinerIds: voteInfo.MinerIds,
4343
ActorId: voteInfo.OwnerId,
44-
GithubAccount: voteInfo.GithubId,
44+
GithubAccount: voteInfo.GithubName,
4545
}, nil
4646

4747
}

backend/build.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/bash
22
set -e
33

4-
IMAGE_NAME="pv-test-backend"
4+
IMAGE_NAME="pv-backend-mainnet"
55

6-
if [ ! -f "configuration.yaml" ]; then
7-
echo "Error: configuration.yaml does not exist."
6+
if [ ! -f ".env" ]; then
7+
echo "Error: .env does not exist."
88
exit 1
99
fi
1010

11-
PORT=$(awk '/^server:/{flag=1;next} /^ port:/{if(flag) print $2; flag=0}' "configuration.yaml" | tr -d ':')
11+
PORT=$(awk -F'=' '/^PORT=/ {gsub(/[^0-9]/, "", $2); print $2}' .env)
1212

1313
if [ -z "$PORT" ]; then
14-
echo "Error: Can not get port from configuration."
14+
echo "Error: Can not get port from .env."
1515
exit 1
1616
fi
1717

@@ -38,4 +38,4 @@ else
3838
echo "Container $IMAGE_NAME does not exist or is already stopped."
3939
fi
4040

41-
docker run --name $IMAGE_NAME -v ./configuration.yaml:/dist/configuration.yaml -p $PORT:$PORT -d $IMAGE_NAME
41+
docker run --name $IMAGE_NAME -p $PORT:$PORT -d $IMAGE_NAME

backend/config/config.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func InitConfig(path string) {
6161
replacedValue = strings.ReplaceAll(replacedValue, "'", "")
6262
replacedValue = strings.ReplaceAll(replacedValue, "\"", "")
6363

64-
if key == "xxl-job.serveraddrs" {
64+
if key == "github.token" {
6565
viper.Set(key, strings.Split(replacedValue, ","))
6666
} else {
6767
viper.Set(key, replacedValue)
@@ -82,3 +82,49 @@ func replaceEnvVariables(value string) string {
8282
return os.Getenv(key)
8383
})
8484
}
85+
86+
func GetDefaultConfig(client ...*Config) {
87+
Client = DefaultConfig
88+
if len(client) == 0 {
89+
return
90+
}
91+
92+
var config *Config = client[0]
93+
if client != nil {
94+
if config.Server.Port != "" {
95+
Client.Server.Port = config.Server.Port
96+
}
97+
98+
if config.Server.RpcPort != "" {
99+
Client.Server.RpcPort = config.Server.RpcPort
100+
}
101+
102+
if config.Network.ChainId != 0 {
103+
Client.Network.ChainId = config.Network.ChainId
104+
}
105+
106+
if config.Network.Name != "" {
107+
Client.Network.Name = config.Network.Name
108+
}
109+
110+
if config.Network.Rpc != "" {
111+
Client.Network.Rpc = config.Network.Rpc
112+
}
113+
114+
if config.Network.MinerIdPrefix != "" {
115+
Client.Network.MinerIdPrefix = config.Network.MinerIdPrefix
116+
}
117+
118+
}
119+
120+
}
121+
122+
var DefaultConfig = Config{
123+
Server: Server{Port: "8000", RpcPort: "9000"},
124+
Network: Network{
125+
ChainId: 314159,
126+
Name: "FileCoin-Calibration ",
127+
Rpc: "https://filecoin-calibration.chainup.net/rpc/v1",
128+
MinerIdPrefix: "t0",
129+
},
130+
}

backend/config/types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Config struct {
2222
Snapshot Snapshot // Snapshot configuration
2323
Network Network // List of network configurations
2424
ABIPath ABIPath // Abi path to the contracts
25+
Github Github // Github configuration
2526
}
2627

2728
// Server represents the server configuration.
@@ -43,6 +44,10 @@ type Drand struct {
4344
ChainHash string // Chain hash for the Drand network
4445
}
4546

47+
type Github struct {
48+
Token []string
49+
}
50+
4651
// Network represents the configuration for a specific network.
4752
type Network struct {
4853
ChainId int64 // Unique identifier for the network
@@ -51,7 +56,6 @@ type Network struct {
5156
PowerVotingContract string // Contract address for PowerVoting
5257
SyncEventStartHeight int64 // Deployment height of the PowerVoting contract
5358
OracleContract string // Contract address for Oracle
54-
OraclePowersContract string // Contract address for OraclePowers
5559
FipContract string // Contract address for FIP
5660
FipInitEditor string // Initial editor for FIP
5761
MinerIdPrefix string // Prefix for miner IDs
@@ -64,6 +68,5 @@ type Snapshot struct {
6468
type ABIPath struct {
6569
PowerVotingAbi string // ABI (Application Binary Interface) for PowerVoting contract
6670
OracleAbi string // ABI for Oracle contract
67-
OraclePowersAbi string // ABI for OraclePowers contract
6871
FipAbi string // ABI for FIP contract
6972
}

0 commit comments

Comments
 (0)