Skip to content

Commit

Permalink
geodnet test fix (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhiran authored Jan 13, 2025
1 parent a458a32 commit 283aae1
Show file tree
Hide file tree
Showing 18 changed files with 571 additions and 449 deletions.
2 changes: 2 additions & 0 deletions datasource/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (p *Clickhouse) conv(dt *db.Task) (*task.Task, error) {
DevicePubKey: pubkey,
Payload: []byte(dt.Payload),
Signature: sig,
PayloadHash: common.HexToHash(dt.PayloadHash),
TaskHash: common.HexToHash(dt.TaskHash),
}, nil
}

Expand Down
14 changes: 7 additions & 7 deletions docs/geod.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ need the tools for interacting with smart contracts

### Testnet

#### bind dapp
#### bind w3bstream project
```bash
cast send 0x74309Bc83fF7Ba8aBaB901936927976792a6d9B6 "bindDapp(uint256,address)" 942 0xB2Dda5D9E65E44749409E209d8b7b15fb4e82147 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
cast send 0xB564996622CE5610b9cF4ed35160f406185d7d0b "register(uint256)" 942 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
```

#### bind w3bstream project
```bash
cast send 0x74309Bc83fF7Ba8aBaB901936927976792a6d9B6 "register(uint256)" 942 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
cast send 0x7D3158166E9298fC47beA036fE162fEA17632E5D "updateConfig(uint256,string,bytes32)" 942 ipfs://ipfs.mainnet.iotex.io/QmUHfDnvWrr2wiC78dw85xfctzawNWAN1TEbzosxwHdzYC 0x8153291c230dd107f102f75e826a11d9d4a8ac3f0f4e1c3619e547f82a94410e --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
```
```bash
cast send 0x0abec44FC786e8da12267Db5fdeB4311AD1A0A8A "updateConfig(uint256,string,bytes32)" 942 ipfs://ipfs.mainnet.iotex.io/QmUHfDnvWrr2wiC78dw85xfctzawNWAN1TEbzosxwHdzYC 0x8153291c230dd107f102f75e826a11d9d4a8ac3f0f4e1c3619e547f82a94410e --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
cast send 0x7D3158166E9298fC47beA036fE162fEA17632E5D "resume(uint256)" 942 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
```

#### bind dapp
```bash
cast send 0x0abec44FC786e8da12267Db5fdeB4311AD1A0A8A "resume(uint256)" 942 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
cast send 0x19dD7163Ad80fE550C97Affef49E1995B24941B1 "bindDapp(uint256,address)" 942 0xB2Dda5D9E65E44749409E209d8b7b15fb4e82147 --private-key "your private key" --rpc-url "https://babel-api.testnet.iotex.io" --legacy
```
22 changes: 10 additions & 12 deletions service/apinode/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ func Run(projectManager *project.Manager, db *apidb.DB, sequencerAddr string, in
continue
}

tasksByProject := make(map[string][]*apidb.Task)
taskMap := make(map[string][]*apidb.Task)
for i := range ts {
tasksByProject[ts[i].ProjectID] = append(tasksByProject[ts[i].ProjectID], ts[i])
k := ts[i].ProjectID + "_" + ts[i].DevicePubKey
taskMap[k] = append(taskMap[k], ts[i])
}

for pidStr, tasks := range tasksByProject {
pid, ok := new(big.Int).SetString(pidStr, 10)
for _, tasks := range taskMap {
pid, ok := new(big.Int).SetString(tasks[0].ProjectID, 10)
if !ok {
slog.Error("failed to decode project id string", "project_string", pidStr)
slog.Error("failed to decode project id string", "project_string", tasks[0].ProjectID)
continue
}
p, err := projectManager.Project(pid)
if err != nil {
slog.Error("failed to get project", "error", err, "project_id", pidStr)
slog.Error("failed to get project", "error", err, "project_id", pid.String())
continue
}
// TODO support project config
cfg, err := p.DefaultConfig()
if err != nil {
slog.Error("failed to get project config", "error", err, "project_id", pidStr)
slog.Error("failed to get project config", "error", err, "project_id", pid.String())
continue
}
if cfg.ProofType == "movement" && len(tasks) > 0 {
if cfg.ProofType == "movement" {
prevTaskID := tasks[0].TaskID
tasks[len(tasks)-1].PrevTaskID = prevTaskID
}
Expand All @@ -62,10 +63,7 @@ func Run(projectManager *project.Manager, db *apidb.DB, sequencerAddr string, in
continue
}

for _, tasks := range tasksByProject {
if len(tasks) == 0 {
continue
}
for _, tasks := range taskMap {
lastTask := tasks[len(tasks)-1]
if err := notify(sequencerAddr, common.HexToHash(lastTask.TaskID)); err != nil {
slog.Error("failed to notify sequencer", "error", err)
Expand Down
6 changes: 4 additions & 2 deletions service/apinode/api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ func (s *httpServer) createTask(c *gin.Context) {
return
}

_, hash, hashAlg, _, err := HashTask(req, cfg)
payloadHash, finalHash, hashAlg, _, err := HashTask(req, cfg)
if err != nil {
slog.Error("failed to hash request", "error", err)
c.JSON(http.StatusBadRequest, newErrResp(errors.Wrap(err, "failed to hash request")))
return
}
recovered, sigAlg, err := recover(hash, sig, cfg)
recovered, sigAlg, err := recover(finalHash, sig, cfg)
if err != nil {
slog.Error("failed to recover public key", "error", err)
c.JSON(http.StatusBadRequest, newErrResp(errors.Wrap(err, "invalid signature; could not recover public key")))
Expand Down Expand Up @@ -212,6 +212,8 @@ func (s *httpServer) createTask(c *gin.Context) {
Signature: hexutil.Encode(sig),
SignatureAlgorithm: sigAlg,
HashAlgorithm: hashAlg,
PayloadHash: hexutil.Encode(payloadHash[:]),
TaskHash: hexutil.Encode(finalHash[:]),
CreatedAt: time.Now(),
},
); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions service/apinode/db/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Task struct {
Signature string `ch:"signature" gorm:"not null"`
SignatureAlgorithm string `ch:"signature_algorithm" gorm:"not null"`
HashAlgorithm string `ch:"hash_algorithm" gorm:"not null"`
PayloadHash string `ch:"payload_hash" gorm:"not null"`
TaskHash string `ch:"task_hash" gorm:"not null"`
CreatedAt time.Time `ch:"created_at" gorm:"not null"`
PrevTaskID string `ch:"previous_task_id" gorm:"not null"`
}
Expand Down Expand Up @@ -63,6 +65,8 @@ func migrateCH(conn driver.Conn) error {
signature String NOT NULL,
signature_algorithm String NOT NULL,
hash_algorithm String NOT NULL,
payload_hash String NOT NULL,
task_hash String NOT NULL,
created_at DateTime NOT NULL,
previous_task_id String NOT NULL
)
Expand Down
Loading

0 comments on commit 283aae1

Please sign in to comment.