gas

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 4 Imported by: 0

README

Gas SDK

The SDK of Gas APIs.

接入流程

1. 注册七牛账号

如果还没有七牛账号,可以在这里注册

2. 添加用户级别的配置信息

需要准备以下信息

MaxBaseFee: BaseFee 阈值(高于这个数值一定不划算,避免极端的高 BaseFee),单位 `nanoFil`
MinerIDs: 当前账号所对应的 miner ID 列表

将帐号信息 + 以上配置信息同步给我们,我们在后台添加即可

3. miner 通过 SDK 接入,完成动作(Action)的打点(标记)

Gas 提供基于 Golang 的 SDK,对应的 module 为 github.com/bachue/qiniu-go-sdk-2/gas,这里通过引入 SDK,在每个 Action 的开始/完成时调用接口进行打点即可;具体的配置及使用如下

import (
	qgas "github.com/bachue/qiniu-go-sdk-2/gas"
)

func main() {

	// 对 SDK 的配置
	config := qgas.Config{
		MinerID:   "f23423", // 当前任务对应的 miner ID
		AccessKey: <Qiniu AccessKey>, // 用户在七牛的 AccessKey,可以在 https://portal.qiniu.com/user/key 页面查看
		SecretKey: <Qiniu SecretKey>, // 用户在七牛的 SecretKey https://portal.qiniu.com/user/key 页面查看
	}

	// 构造 SDK
	g := qgas.NewQGas(&config)

	// 当前 sealing 行为的标识(对当前 miner 唯一),可以使用 `SectorNumber` 作为 sealingID
	var sealingID string

	// 标记动作的开始
	g.StartAction(sealingID, qgas.ActionPreCommit) // g.StartAction(<SealingID>, <Action>)
	// 标记动作的结束
	g.EndAction(sealingID, qgas.ActionPreCommit) // g.EndAction(<SealingID>, <Action>)
	// 标记 sealing 过程的取消/中止(注意这里不是指 sector 生命周期的中止)
	g.CancelSealing(sealingID) // g.CancelSealing(<SealingID>)
}

关于动作(Action)的定义,详见下方 Action

标记 sealing 过程的取消(CancelSealing)的合适的时机是决定放弃某个未完成的 sealing 过程、不再继续时;以 Lotus 为例,适合执行 CancelSealing 的时机一般是以下两处:

  1. storage-sealing 模块中对 event 进行 plan 遇到错误的时候:

    https://github.com/filecoin-project/lotus/blob/50b4ea30836618d199e24024f4f591de3dfbb516/extern/storage-sealing/fsm.go#L28

    if err != nil {
    	log.Errorf("unhandled sector error (%d): %+v", si.SectorNumber, err)
    	// 一般来说这里发生错误不会再有重试的机制了,故标记下取消
    	g.CancelSealing(sealingID)
    	return nil
    }
    
  2. 对未成功封装的 sector 执行清除动作的时候

4. miner 通过 SDK 完成决策逻辑的接入

决策逻辑预期在完成打点接入且基于打点数据完成效果评估完成后接入

通过在执行具体的 Action 前调用 SDK 提供的 Wait 方法,可以接入七牛提供的决策逻辑;Wait 会阻塞当前的 goroutine,直到当前时机被判定为适合执行目标动作,具体代码示例如下:

func main() {
	// 完成 Commit 的工作

	// 等待 Action 执行的合适时机,目前我们只支持对于 Action SubmitProveCommit 的决策
	// 这里的 g 即上边通过 qgas.NewQGas(&config) 构造出来的实例
	g.Wait(sealingID, qgas.ActionSubmitProveCommit) // g.Wait(<SealingID>, <Action>)

	// 将 ProveCommit 消息上链
}

Action

Action 是 sector sealing 过程中的动作,每个 Action 都会有开始和完成,通过对每个 sealing 过程 Action 的开始 & 完成时间点的记录,我们可以了解宏观的生产、堆积情况,以便做出决策;目前我们关心的 Action 有以下四个:

ActionPreCommit

对应 Pre Commit 的过程,包括 preCommit phase 1 & preCommit phase 2

ActionSubmitPreCommit

对应 PreCommitSector 消息提交上链的过程,在广播消息前标记动作的开始,在确认消息成功上链后标记动作的完成

ActionCommit

对应 Commit 的过程,包括 commit phase 1 & commit phase 2,标记该动作开始时 WaitSeed 的过程应当已完成,标记该动作结束时意味着可以马上开始做 ProveCommitSector 消息的上链

ActionSubmitProveCommit

对应 ProveCommitSector 消息提交上链的过程,在广播消息前标记动作的开始,在确认消息成功上链后标记动作的完成

Documentation

Index

Constants

View Source
const (
	// ActionPreCommit 对应 Pre Commit 的过程
	ActionPreCommit = "PreCommit"
	// ActionSubmitPreCommit 对应 PreCommitSector 消息上链的过程
	ActionSubmitPreCommit = "SubmitPreCommit"
	// ActionCommit 对应 Commit 的过程
	ActionCommit = "Commit"
	// ActionSubmitProveCommit 对应 ProveCommitSector 消息上链的过程
	ActionSubmitProveCommit = "SubmitProveCommit"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckActionData

type CheckActionData = clt.CheckActionData

type Config

type Config = cfg.Config

Config 是对于 SDK 行为的配置

type QGas

type QGas struct {
	// contains filtered or unexported fields
}

func NewQGas

func NewQGas(config *Config) *QGas

NewQGas 用于构造 QGas 对象

func (*QGas) CancelSealing

func (q *QGas) CancelSealing(sealingID string) error

CancelSealing 标记当前 sector sealing 行为取消

func (*QGas) CheckAction

func (q *QGas) CheckAction(sealingID string, action string, t *int64) (*CheckActionData, error)

func (*QGas) EndAction

func (q *QGas) EndAction(sealingID, action string) error

EndAction 标记动作的结束

func (*QGas) GetSealing

func (q *QGas) GetSealing(sealingID string) (*SealingData, error)

GetSealing 获取当前 sector sealing 条目信息

func (*QGas) Request

func (q *QGas) Request(method, path string, reqData interface{}, respData interface{}) (err error)

func (*QGas) StartAction

func (q *QGas) StartAction(sealingID, action string) error

StartAction 标记动作的开始

func (*QGas) Wait

func (q *QGas) Wait(sealingID string, action string) error

Wait 会阻塞当前工作,直到系统认为当前时间适合执行目标 action

type SealingData

type SealingData = clt.SealingData

SealingData 是 sealing 条目的内容

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL