monitor

package
v0.0.0-...-8165c13 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScanSideChainInterval = 6 * time.Second
	SendHandleUtxoDelay   = 12 * 60 // 22 * 60
	RescanThreshold       = 3
	ThresholdIn24Hours    = 9_8000_0000 //1000_0000_0000 // 1000 BCH

)
View Source
const (
	ToBeRecognized     = 1
	Redeemable         = 2
	LostAndFound       = 3
	LostAndReturn      = 4
	LostAndReturnToDel = 5
	Redeeming          = 6
	RedeemingToDel     = 7
	HandingOver        = 8
	HandedOver         = 9

	MaxAmount = 1000 * 10000_0000 //1000 BCH
)
View Source
const (
	FromRedeemable   = uint8(0) // when it's redeemed
	FromLostAndFound = uint8(1) // when it's redeemed or deleted
	FromRedeeming    = uint8(2) // when it's deleted
	FromBurnRedeem   = uint8(9) // when it's automatically redeemed to burning address

	ZeroX24Json = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"
)
View Source
const (
	ErrCountThreshold = 3
)
View Source
const RetryThreshold = 10

Variables

View Source
var (
	MyPrivKey *ecdsa.PrivateKey
	MyAddress common.Address

	CCAddress = common.HexToAddress("0x0000000000000000000000000000000000002714")
)
View Source
var (
	NetParams         = &chaincfg.TestNet3Params //&chaincfg.MainNetParams
	CCContractAddress = [20]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x27, 0x14}
)
View Source
var (
	ErrNoBlockFoundAtGivenHeight = errors.New("No Block Found at the Given Height")

	EventNewRedeemable   = crypto.Keccak256Hash([]byte("NewRedeemable(uint256,uint32,address)"))
	EventNewLostAndFound = crypto.Keccak256Hash([]byte("NewLostAndFound(uint256,uint32,address)"))
	EventRedeem          = crypto.Keccak256Hash([]byte("Redeem(uint256,uint32,address,uint8)"))
	EventChangeAddr      = crypto.Keccak256Hash([]byte("ChangeAddr(address,address)"))
	EventConvert         = crypto.Keccak256Hash([]byte("Convert(uint256,uint32,address,uint256,uint32,address)"))
	EventDeleted         = crypto.Keccak256Hash([]byte("Deleted(uint256,uint32,address,uint8)"))

	// main chain burn address legacy format: 1SmartBCHBurnAddressxxxxxxy31qJGb
	MainChainBurningAddress string = "qqzdl8vlah353f0cyvmuapag9xlzyq9w6cul36akp5" //cash address format
	BurnAddressMainChain           = "04df9d9fede348a5f82337ce87a829be2200aed6"   //match smartbchd events
)

Functions

func Catchup

func Catchup(bs *BlockScanner)

catch up the latest height of smartBCH

func DebugWatcher

func DebugWatcher()

func EncryptPrivKey

func EncryptPrivKey()

Used by the person who keeps the monitor's private key

func GetCcInfosForTest

func GetCcInfosForTest(ctx context.Context, client *rpc.Client) (res cctypes.CCInfosForTest)

func InitMetaInfo

func InitMetaInfo(tx *gorm.DB, info *MetaInfo)

func InitTotalAmount

func InitTotalAmount(tx *gorm.DB)

func LoadPrivKeyInHex

func LoadPrivKeyInHex(inputHex string)

func MainLoop

func MainLoop(bs *BlockScanner, watcher *OperatorsWatcher)

func MigrateSchema

func MigrateSchema(db *gorm.DB)

func OpenDB

func OpenDB(path string) *gorm.DB

func PrintTotalAmount

func PrintTotalAmount(totalAmount TotalAmount, info cctypes.CCInfosForTest)

func ReadPrivKey

func ReadPrivKey()

func ScriptHashToAddr

func ScriptHashToAddr(h []byte) string

func SendPauseAndResume

func SendPauseAndResume(bs *BlockScanner)

func SendStartRescanAndHandleUTXO

func SendStartRescanAndHandleUTXO(ctx context.Context, rawclient *rpc.Client, client *ethclient.Client, bchClient *rpcclient.Client, lastRescanHeight, lastRescanTime, handleUtxoDelay int64)

A simple function. Just used during debug.

func TriggerDamageControl

func TriggerDamageControl(ctx context.Context, bs *BlockScanner, watcher *OperatorsWatcher, fatalErr *FatalError)

Types

type Block

type Block struct {
	Transactions []*Transaction `json:"transactions"`
}

type BlockScanner

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

Scan blocks of side chain and main chain

func NewBlockScanner

func NewBlockScanner(bchClient *rpcclient.Client, db *gorm.DB, sideChainUrl string) *BlockScanner

func (*BlockScanner) CheckMainChainForRescan

func (bs *BlockScanner) CheckMainChainForRescan(metaInfo MetaInfo) (err error, lastFinalizedHeight int64)

func (*BlockScanner) CheckSlidingWindow

func (bs *BlockScanner) CheckSlidingWindow(ctx context.Context, timestamp int64, metaInfo *MetaInfo)

according to the sum in sliding window, pause/resume the shagate logic

func (*BlockScanner) GetBlockTime

func (bs *BlockScanner) GetBlockTime(ctx context.Context, blockHeight int64) (int64, error)

func (*BlockScanner) ScanBlock

func (bs *BlockScanner) ScanBlock(ctx context.Context, timestamp, blockHeight int64) error

type BlockWatcher

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

Watches the blocks of main chain

func (*BlockWatcher) HandleMainChainBlock

func (bw *BlockWatcher) HandleMainChainBlock(blockHeight int64) error

type CCTxCounter

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

accumulate the cc-transactions on main chain

func (*CCTxCounter) CheckMainChainBlock

func (txc *CCTxCounter) CheckMainChainBlock(gormTx *gorm.DB, blockHeight int64) (err error, isFinalized bool)

if the block at 'blockHeight' is finalized, analyze its transactions to increase 'ccTxCount' if the block exists (no matter finalized or not), check evil transactions in it.

type CcUtxo

type CcUtxo struct {
	gorm.Model
	Type         int
	CovenantAddr string
	RedeemTarget string
	Amount       int64
	Txid         string
	Vout         uint32
	NewTxid      string
	NewVout      uint32
}

type ConvertParams

type ConvertParams struct {
	Txid         common.Hash
	Vout         uint32
	CovenantAddr common.Address
}

type FatalError

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

func NewFatal

func NewFatal(s string) *FatalError

func (*FatalError) Error

func (e *FatalError) Error() string

type Log

type Log struct {
	Address     string   `json:"address"`
	Topics      []string `json:"topics"`
	Data        string   `json:"data"`
	BlockNumber string   `json:"blockNumber"`
	TxHash      string   `json:"txHash"`
	TxIndex     string   `json:"txIndex"`
	BlockHash   string   `json:"blockHash"`
	Index       string   `json:"index"`
	Removed     bool     `json:"removed"`
}

type MetaInfo

type MetaInfo struct {
	gorm.Model
	LastRescanTime   int64
	ScannedHeight    int64
	MainChainHeight  int64
	SideChainHeight  int64
	CurrCovenantAddr string
	LastCovenantAddr string
	AmountX24        string // The total amount transferred in each hour in the past 24 hours
	TimestampX24     string // the corresponding hour-number of the slots in AmountX24
}

type OperatorsWatcher

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

func NewOperatorsWatcher

func NewOperatorsWatcher(sbchClient *sbch.SimpleRpcClient, opClients []*opclient.Client) *OperatorsWatcher

func (*OperatorsWatcher) CheckNodes

func (watcher *OperatorsWatcher) CheckNodes() error

func (*OperatorsWatcher) CheckUtxoLists

func (watcher *OperatorsWatcher) CheckUtxoLists() error

func (*OperatorsWatcher) CheckUtxoListsAgainstDB

func (watcher *OperatorsWatcher) CheckUtxoListsAgainstDB(db *gorm.DB) *FatalError

func (*OperatorsWatcher) GetUtxoListsFromSbch

func (watcher *OperatorsWatcher) GetUtxoListsFromSbch() (utxoLists UtxoLists, err error)

type TotalAmount

type TotalAmount struct {
	gorm.Model
	TotalRedeemAmountS2M       int64
	TotalRedeemNumsS2M         int64
	TotalLostAndFoundAmountS2M int64
	TotalLostAndFoundNumsS2M   int64
	TotalTransferAmountM2S     int64
	TotalTransferNumsM2S       int64
	TotalTransferByBurnAmount  int64
	TotalTransferByBurnNums    int64
}

type Transaction

type Transaction struct {
	Hash              string `json:"hash"`
	TransactionIndex  string `json:"transactionIndex"`
	Nonce             string `json:"nonce"`
	BlockHash         string `json:"blockHash"`
	BlockNumber       string `json:"blockNumber"`
	From              string `json:"from"`
	To                string `json:"to"`
	Value             string `json:"value"`
	GasPrice          string `json:"gasPrice"`
	Gas               string `json:"gas"`
	Input             string `json:"input"`
	CumulativeGasUsed string `json:"cumulativeGasUsed"`
	GasUsed           string `json:"gasUsed"`
	ContractAddress   string `json:"contractAddress"`
	Logs              []Log  `json:"logs"`
	LogsBloom         string `json:"logsBloom"`
	Status            string `json:"status"`
	StatusStr         string `json:"statusStr"`
	OutData           string `json:"outData"`
}

type UtxoLists

type UtxoLists struct {
	RedeemingUtxosForOperators     []*sbchrpctypes.UtxoInfo
	RedeemingUtxosForMonitors      []*sbchrpctypes.UtxoInfo
	ToBeConvertedUtxosForOperators []*sbchrpctypes.UtxoInfo
	ToBeConvertedUtxosForMonitors  []*sbchrpctypes.UtxoInfo
}

func GetUtxoListsFromOperator

func GetUtxoListsFromOperator(opClient *opclient.Client) (utxoLists UtxoLists, err error)

Jump to

Keyboard shortcuts

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