OSDN Git Service

add colect_minutes
authorHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 00:04:57 +0000 (08:04 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 00:04:57 +0000 (08:04 +0800)
cmd/fedd/main.go
docs/federation/README-en.md
federation/config/config.go
federation/warder.go

index 5e886a2..26c22c5 100644 (file)
@@ -22,7 +22,7 @@ func main() {
        txCh := make(chan *orm.CrossTransaction)
        go synchron.NewMainchainKeeper(db, &cfg.Mainchain, txCh).Run()
        go synchron.NewSidechainKeeper(db, &cfg.Sidechain, txCh).Run()
-       go federation.NewWarder(db, txCh).Run()
+       go federation.NewWarder(cfg, db, txCh).Run()
 
        // keep the main func running in case of terminating goroutines
        var wg sync.WaitGroup
index c6e05b9..d835b81 100644 (file)
@@ -25,6 +25,7 @@ A `fed_cfg.json` would look like this:
         },
         "log_mode" : true
     },
+    "collect_unsubimmited_minutes" : 5,
     "warders" : [
         {
             "position" : 1,
index d09a394..31c8a4b 100644 (file)
@@ -33,11 +33,12 @@ func NewConfigWithPath(path string) *Config {
 }
 
 type Config struct {
-       GinGonic    GinGonic    `json:"gin-gonic"`
-       MySQLConfig MySQLConfig `json:"mysql"`
-       Warders     []Warder    `json:"warders"`
-       Mainchain   Chain       `json:"mainchain"`
-       Sidechain   Chain       `json:"sidechain"`
+       GinGonic       GinGonic    `json:"gin-gonic"`
+       MySQLConfig    MySQLConfig `json:"mysql"`
+       CollectMinutes uint64      `json:"collect_unsubimmited_minutes"`
+       Warders        []Warder    `json:"warders"`
+       Mainchain      Chain       `json:"mainchain"`
+       Sidechain      Chain       `json:"sidechain"`
 }
 
 type GinGonic struct {
index 1a81e4f..b839e05 100644 (file)
@@ -2,6 +2,7 @@ package federation
 
 import (
        "database/sql"
+       "time"
 
        "github.com/jinzhu/gorm"
        log "github.com/sirupsen/logrus"
@@ -9,22 +10,28 @@ import (
 
        "github.com/vapor/errors"
        "github.com/vapor/federation/common"
+       "github.com/vapor/federation/config"
        "github.com/vapor/federation/database/orm"
        vaporTypes "github.com/vapor/protocol/bc/types"
 )
 
 type warder struct {
-       db   *gorm.DB
-       txCh chan *orm.CrossTransaction
+       colletInterval time.Duration
+       db             *gorm.DB
+       txCh           chan *orm.CrossTransaction
 }
 
-func NewWarder(db *gorm.DB, txCh chan *orm.CrossTransaction) *warder {
+func NewWarder(cfg *config.Config, db *gorm.DB, txCh chan *orm.CrossTransaction) *warder {
        return &warder{
-               txCh: txCh,
+               colletInterval: time.Duration(cfg.CollectMinutes) * time.Minute,
+               db:             db,
+               txCh:           txCh,
        }
 }
 
 func (w *warder) Run() {
+       go w.collectUnsubmittedTx()
+
        for ormTx := range w.txCh {
                if err := w.validateCrossTx(ormTx); err != nil {
                        log.Warnln("invalid cross-chain tx", ormTx)
@@ -64,6 +71,10 @@ func (w *warder) Run() {
        }
 }
 
+func (w *warder) collectUnsubmittedTx() {
+
+}
+
 func (w *warder) validateCrossTx(tx *orm.CrossTransaction) error {
        if tx.Status == common.CrossTxRejectedStatus {
                return errors.New("cross-chain tx rejeted")