Skip to content

Commit

Permalink
fix: update parent_key field to varchar(2048) (#5317)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode authored Sep 23, 2022
1 parent 6afaaf6 commit 4209f7f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/chainsync/slashfilter/mysqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ type MysqlSlashFilter struct {
_db *gorm.DB
}

//MinedBlock record mined block
// MinedBlock record mined block
type MinedBlock struct {
ParentEpoch int64 `gorm:"column:parent_epoch;type:bigint(20);NOT NULL"`
ParentKey string `gorm:"column:parent_key;type:varchar(1000);NOT NULL"`
ParentKey string `gorm:"column:parent_key;type:varchar(2048);NOT NULL"`

Epoch int64 `gorm:"column:epoch;type:bigint(20);NOT NULL"`
Miner string `gorm:"column:miner;type:varchar(256);NOT NULL"`
Cid string `gorm:"column:cid;type:varchar(256);NOT NULL"`
}

//NewMysqlSlashFilter create a new slash filter base on mysql database
// NewMysqlSlashFilter create a new slash filter base on mysql database
func NewMysqlSlashFilter(cfg config.MySQLConfig) (ISlashFilter, error) {
db, err := gorm.Open(mysql.Open(cfg.ConnectionString))
if err != nil {
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewMysqlSlashFilter(cfg config.MySQLConfig) (ISlashFilter, error) {
}, nil
}

//checkSameHeightFault check whether the miner mined multi block on the same height
// checkSameHeightFault check whether the miner mined multi block on the same height
func (f *MysqlSlashFilter) checkSameHeightFault(bh *types.BlockHeader) error {
var bk MinedBlock
err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and epoch=?", bh.Miner.String(), bh.Height).Error
Expand All @@ -86,7 +86,7 @@ func (f *MysqlSlashFilter) checkSameHeightFault(bh *types.BlockHeader) error {

}

//checkSameParentFault check whether the miner mined block on the same parent
// checkSameParentFault check whether the miner mined block on the same parent
func (f *MysqlSlashFilter) checkSameParentFault(bh *types.BlockHeader) error {
var bk MinedBlock
err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and parent_key=?", bh.Miner.String(), types.NewTipSetKey(bh.Parents...).String()).Error
Expand All @@ -107,7 +107,7 @@ func (f *MysqlSlashFilter) checkSameParentFault(bh *types.BlockHeader) error {

}

//MinedBlock check whether the block mined is slash
// MinedBlock check whether the block mined is slash
func (f *MysqlSlashFilter) MinedBlock(ctx context.Context, bh *types.BlockHeader, parentEpoch abi.ChainEpoch) error {
if err := f.checkSameHeightFault(bh); err != nil {
return err
Expand Down

0 comments on commit 4209f7f

Please sign in to comment.