Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor storage #236

Open
wants to merge 6 commits into
base: gethintegration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/shisui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ethereum/go-ethereum/portalnetwork/portalwire"
"github.com/ethereum/go-ethereum/portalnetwork/state"
"github.com/ethereum/go-ethereum/portalnetwork/storage"
"github.com/ethereum/go-ethereum/portalnetwork/storage/sqlite"
"github.com/ethereum/go-ethereum/portalnetwork/web3"
"github.com/ethereum/go-ethereum/rpc"
"github.com/mattn/go-isatty"
Expand Down Expand Up @@ -372,11 +373,11 @@ func doPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) {

func initHistory(config Config, server *rpc.Server, conn discover.UDPConn, localNode *enode.LocalNode, discV5 *discover.UDPv5, utp *portalwire.PortalUtp) (*history.Network, error) {
networkName := portalwire.History.Name()
db, err := history.NewDB(config.DataDir, networkName)
db, err := sqlite.NewDB(config.DataDir, networkName)
if err != nil {
return nil, err
}
contentStorage, err := history.NewHistoryStorage(storage.PortalStorageConfig{
contentStorage, err := sqlite.NewHistoryStorage(storage.PortalStorageConfig{
StorageCapacityMB: config.DataCapacity,
DB: db,
NodeId: localNode.ID(),
Expand Down Expand Up @@ -466,11 +467,11 @@ func initBeacon(config Config, server *rpc.Server, conn discover.UDPConn, localN

func initState(config Config, server *rpc.Server, conn discover.UDPConn, localNode *enode.LocalNode, discV5 *discover.UDPv5, utp *portalwire.PortalUtp) (*state.StateNetwork, error) {
networkName := portalwire.State.Name()
db, err := history.NewDB(config.DataDir, networkName)
db, err := sqlite.NewDB(config.DataDir, networkName)
if err != nil {
return nil, err
}
contentStorage, err := history.NewHistoryStorage(storage.PortalStorageConfig{
contentStorage, err := sqlite.NewHistoryStorage(storage.PortalStorageConfig{
StorageCapacityMB: config.DataCapacity,
DB: db,
NodeId: localNode.ID(),
Expand Down
4 changes: 4 additions & 0 deletions portalnetwork/beacon/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func (bs *Storage) Radius() *uint256.Int {
return storage.MaxDistance
}

func (bs *Storage) Close() error {
return bs.db.Close()
}

func (bs *Storage) getContentValue(contentId []byte) ([]byte, error) {
res := make([]byte, 0)
err := bs.db.QueryRowContext(context.Background(), ContentValueLookupQueryBeacon, contentId).Scan(&res)
Expand Down
Loading