work on wasm watchers
This commit is contained in:
@@ -19,15 +19,21 @@ package eth
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/watcher/shared"
|
||||
)
|
||||
|
||||
var (
|
||||
vacuumThreshold int64 = 5000 // dont know how to decided what this should be set to
|
||||
)
|
||||
|
||||
// Repository is the underlying struct for satisfying the shared.Repository interface for eth
|
||||
type Repository struct {
|
||||
db *postgres.DB
|
||||
triggerFunctions [][2]string
|
||||
deleteCalls int64
|
||||
}
|
||||
|
||||
// NewRepository returns a new eth.Repository that satisfies the shared.Repository interface
|
||||
@@ -35,6 +41,7 @@ func NewRepository(db *postgres.DB, triggerFunctions [][2]string) shared.Reposit
|
||||
return &Repository{
|
||||
db: db,
|
||||
triggerFunctions: triggerFunctions,
|
||||
deleteCalls: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +53,42 @@ func (r *Repository) LoadTriggers() error {
|
||||
|
||||
// QueueData puts super node payload data into the db queue
|
||||
func (r *Repository) QueueData(payload super_node.SubscriptionPayload) error {
|
||||
panic("implement me")
|
||||
pgStr := `INSERT INTO eth.queued_data (data, height) VALUES ($1, $2)
|
||||
ON CONFLICT (height) DO UPDATE SET (data) VALUES ($1)`
|
||||
_, err := r.db.Exec(pgStr, payload.Data, payload.Height)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetQueueData grabs super node payload data from the db queue
|
||||
func (r *Repository) GetQueueData(height int64, hash string) (super_node.SubscriptionPayload, error) {
|
||||
panic("implement me")
|
||||
// GetQueueData grabs a chunk super node payload data from the queue table so that it can
|
||||
// be forwarded to the ready table
|
||||
// this is used to make sure we enter data into the ready table in sequential order
|
||||
// even if we receive data out-of-order
|
||||
// it returns the new index
|
||||
// delete the data it retrieves so as to clear the queue
|
||||
func (r *Repository) GetQueueData(height int64) (super_node.SubscriptionPayload, int64, error) {
|
||||
r.deleteCalls++
|
||||
pgStr := `DELETE FROM eth.queued_data
|
||||
WHERE height = $1
|
||||
RETURNING *`
|
||||
var res shared.QueuedData
|
||||
if err := r.db.Get(&res, pgStr, height); err != nil {
|
||||
return super_node.SubscriptionPayload{}, height, err
|
||||
}
|
||||
payload := super_node.SubscriptionPayload{
|
||||
Data: res.Data,
|
||||
Height: res.Height,
|
||||
Flag: super_node.EmptyFlag,
|
||||
}
|
||||
height++
|
||||
// Periodically clean up space in the queue table
|
||||
if r.deleteCalls >= vacuumThreshold {
|
||||
_, err := r.db.Exec(`VACUUM ANALYZE eth.queued_data`)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
r.deleteCalls = 0
|
||||
}
|
||||
return payload, height, nil
|
||||
}
|
||||
|
||||
// ReadyData puts super node payload data in the tables ready for processing by trigger functions
|
||||
|
||||
Reference in New Issue
Block a user