Skip to content

Commit

Permalink
add README, use correct key
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Jan 21, 2025
1 parent 9380d62 commit 37d479e
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 2 deletions.
46 changes: 46 additions & 0 deletions documentation/en/curio-cli/sptool.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COMMANDS:
info Print miner actor info
sectors interact with sector store
proving View proving information
toolbox some tools to fix some problems
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
Expand Down Expand Up @@ -489,3 +490,48 @@ USAGE:
OPTIONS:
--help, -h show help
```

## sptool toolbox
```
NAME:
sptool toolbox - some tools to fix some problems
USAGE:
sptool toolbox command [command options]
COMMANDS:
spark Manage Smart Contract PeerID used by Spark
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```

### sptool toolbox spark
```
NAME:
sptool toolbox spark - Manage Smart Contract PeerID used by Spark
USAGE:
sptool toolbox spark command [command options]
COMMANDS:
delete-peer Delete PeerID from Spark Smart Contract
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```

#### sptool toolbox spark delete-peer
```
NAME:
sptool toolbox spark delete-peer - Delete PeerID from Spark Smart Contract
USAGE:
sptool toolbox spark delete-peer [command options] <Miner ID>
OPTIONS:
--really-do-it Send the message to the smart contract (default: false)
--help, -h show help
```
25 changes: 23 additions & 2 deletions market/ipni/ipni-provider/spark.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,34 @@ import (
)

func (p *Provider) updateSparkContract(ctx context.Context) error {
var priv []byte
var onChainPeerID string

err := p.db.QueryRow(ctx, `select priv_key, peer_id from libp2p LIMIT 1`).Scan(&priv, &onChainPeerID)
if err != nil {
return xerrors.Errorf("querying libp2p peer: %w", err)
}

pKey, err := crypto.UnmarshalPrivateKey(priv)
if err != nil {
return xerrors.Errorf("unmarshaling private key: %w", err)
}

for _, pInfo := range p.keys {
pInfo := pInfo
mInfo, err := p.full.StateMinerInfo(ctx, pInfo.Miner, types.EmptyTSK)
if err != nil {
return err
}

if mInfo.PeerId == nil {
return xerrors.Errorf("peer id not found for miner: %s", pInfo.Miner)
}

if mInfo.PeerId.String() != onChainPeerID {
return xerrors.Errorf("peer id mismatch for miner: %s: onChain: %s and DB: %s", pInfo.Miner, mInfo.PeerId.String(), onChainPeerID)
}

contractID, err := spark.GetContractAddress()
if err != nil {
return err
Expand Down Expand Up @@ -81,7 +102,7 @@ func (p *Provider) updateSparkContract(ctx context.Context) error {
var params []byte

if len(res.MsgRct.Return) == 0 {
params, err = p.getSparkParams(pInfo.SPID, pInfo.ID.String(), pInfo.Key, "add")
params, err = p.getSparkParams(pInfo.SPID, pInfo.ID.String(), pKey, "add")
if err != nil {
return xerrors.Errorf("failed to get spark params for %s: %w", pInfo.Miner.String(), err)
}
Expand All @@ -97,7 +118,7 @@ func (p *Provider) updateSparkContract(ctx context.Context) error {
continue
}

params, err = p.getSparkParams(pInfo.SPID, pInfo.ID.String(), pInfo.Key, "update")
params, err = p.getSparkParams(pInfo.SPID, pInfo.ID.String(), pKey, "update")
if err != nil {
return xerrors.Errorf("failed to get spark params for %s: %w", pInfo.Miner.String(), err)
}
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 37d479e

Please sign in to comment.