Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ee9888e
multi thread queue
dahn510 Apr 9, 2025
b1a0d1a
queue thread config
dahn510 Apr 10, 2025
c6218d4
clarify log messages
dahn510 Apr 10, 2025
66dec99
batch send messages
dahn510 Apr 10, 2025
f0cb595
tweaking queue init
TheMarstonConnell Apr 10, 2025
bb2f201
batch queue
dahn510 Apr 14, 2025
c8abaad
clean up
dahn510 Apr 15, 2025
701304f
channel queue
dahn510 Apr 16, 2025
125c590
replace stop channel with msg output channel
dahn510 Apr 21, 2025
27313d3
send msg to free worker channel
dahn510 Apr 22, 2025
bf12c63
clean up compile errors
dahn510 Apr 24, 2025
5ae1615
tx timer and batch size config
dahn510 Apr 24, 2025
bdf7f77
fix build error
dahn510 Apr 24, 2025
c59f39c
Merge branch 'main' of github.com:JackalLabs/sequoia into multi-queue
dahn510 Apr 24, 2025
534f3e4
max retry error
dahn510 Apr 28, 2025
fbfa225
test max retry
dahn510 Apr 28, 2025
2eed453
worker test
dahn510 May 1, 2025
f78e4b8
mock auth query client
dahn510 May 1, 2025
d200bb4
mock auth client
dahn510 May 2, 2025
f5539f1
mock tx and rpc clients
dahn510 May 3, 2025
dcf3ef2
lint cleanup
dahn510 May 3, 2025
d84c967
test batch full send
dahn510 May 5, 2025
bd6c12e
clean up
dahn510 May 6, 2025
5e06959
wait for workers to terminate
dahn510 May 8, 2025
777f7b1
queue and worker tests
dahn510 May 8, 2025
9fdb0c4
bench pool Add
dahn510 May 8, 2025
8bf2b0f
fake and mock query client
dahn510 May 14, 2025
a89e0db
fake clients
dahn510 May 15, 2025
6f98006
fake methods used by the wallet
dahn510 May 15, 2025
529bffc
create new app with options
dahn510 May 15, 2025
d539b51
add test_mode flag to start cmd
dahn510 May 15, 2025
f1179c5
use query client from app
dahn510 May 15, 2025
e5abf22
add query client to api handler
dahn510 May 15, 2025
5b4afbe
fake query responses to start app
dahn510 May 17, 2025
d4f2d41
fix blockstore key unmarshal error
dahn510 May 20, 2025
1b44ad2
pass query client to stray manager
dahn510 May 21, 2025
186dbf9
tx decoder
dahn510 May 27, 2025
d5cd8df
decode tx sent to fake rpc client
dahn510 May 27, 2025
c216924
register feegrant interface
dahn510 May 28, 2025
b1637f7
fake query file
dahn510 Jun 3, 2025
bd31f2d
use passed query client
dahn510 Jun 3, 2025
166706b
fix race condition of file prove counter
dahn510 Jun 3, 2025
641f4ff
Merge branch 'main' into multi-queue
dahn510 Jun 4, 2025
7198fe3
create offset wallet from main wallet
dahn510 Jun 4, 2025
bbf3ada
fix hands and worker wallet collision
dahn510 Jun 4, 2025
52264ba
Merge branch 'main' into multi-queue
TheMarstonConnell Jun 6, 2025
57fa87d
lint
TheMarstonConnell Jun 6, 2025
ebe4c04
gitignore linting
TheMarstonConnell Jun 9, 2025
a199413
mem leaks maybe?
TheMarstonConnell Jun 9, 2025
4547d2e
Merge pull request #127 from JackalLabs/marston/mem-leaks
dahn510 Jun 9, 2025
bd39aa3
remove wallet offset from new hand
dahn510 Jun 12, 2025
a1aa8ac
fix wrong error reference returned
dahn510 Jun 12, 2025
52c60ed
fix account sequence mismatch
dahn510 Jun 12, 2025
a70c565
fix nil pointer dereference
dahn510 Jun 16, 2025
c9a1a0b
fix provider not found init problem
dahn510 Jun 23, 2025
7d35001
return init provider on chain err
dahn510 Jun 23, 2025
fbd533d
fix sequence mismatch error
dahn510 Jun 30, 2025
210c22c
update test
dahn510 Jul 11, 2025
28579bc
lint
dahn510 Jul 11, 2025
9130089
Merge branch 'main' into multi-queue
dahn510 Jul 11, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ data
sequoia
*.txt
*.json
~
.DS_Store
4 changes: 1 addition & 3 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"github.com/rs/zerolog/log"
)

func SpaceHandler(c *client.Client, address string) func(http.ResponseWriter, *http.Request) {
func SpaceHandler(c *client.Client, queryClient storageTypes.QueryClient, address string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
queryClient := storageTypes.NewQueryClient(c.GRPCConn)

params := &storageTypes.QueryProvider{
Address: address,
}
Expand Down
10 changes: 4 additions & 6 deletions api/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func handleErr(err error, w http.ResponseWriter, code int) {
}
}

func PostFileHandler(fio *file_system.FileSystem, prover *proofs.Prover, wl *wallet.Wallet, chunkSize int64) func(http.ResponseWriter, *http.Request) {
func PostFileHandler(fio *file_system.FileSystem, prover *proofs.Prover, wl *wallet.Wallet, query storageTypes.QueryClient, chunkSize int64) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
err := req.ParseMultipartForm(MaxFileSize) // MAX file size lives here
if err != nil {
Expand Down Expand Up @@ -96,13 +96,12 @@ func PostFileHandler(fio *file_system.FileSystem, prover *proofs.Prover, wl *wal
return
}

cl := storageTypes.NewQueryClient(wl.Client.GRPCConn)
queryParams := storageTypes.QueryFile{
Merkle: merkle,
Owner: sender,
Start: startBlock,
}
res, err := cl.File(context.Background(), &queryParams)
res, err := query.File(context.Background(), &queryParams)
if err != nil {
handleErr(fmt.Errorf("failed to find file on chain with merkle: %x, owner: %s, start: %d | %w", merkle, sender, startBlock, err), w, http.StatusInternalServerError)
return
Expand Down Expand Up @@ -154,7 +153,7 @@ func PostFileHandler(fio *file_system.FileSystem, prover *proofs.Prover, wl *wal
}
}

func PostFileHandlerV2(fio *file_system.FileSystem, prover *proofs.Prover, wl *wallet.Wallet, chunkSize int64) func(http.ResponseWriter, *http.Request) {
func PostFileHandlerV2(fio *file_system.FileSystem, prover *proofs.Prover, wl *wallet.Wallet, queryClient storageTypes.QueryClient, chunkSize int64) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
err := req.ParseMultipartForm(MaxFileSize) // MAX file size lives here
if err != nil {
Expand Down Expand Up @@ -227,13 +226,12 @@ func PostFileHandlerV2(fio *file_system.FileSystem, prover *proofs.Prover, wl *w
log.Error().Err(fmt.Errorf("can't encode json : %w", err))
}

cl := storageTypes.NewQueryClient(wl.Client.GRPCConn)
queryParams := storageTypes.QueryFile{
Merkle: merkle,
Owner: sender,
Start: startBlock,
}
res, err := cl.File(context.Background(), &queryParams)
res, err := queryClient.File(context.Background(), &queryParams)
if err != nil {
log.Error().Err(fmt.Errorf("failed to find file on chain with merkle: %x, owner: %s, start: %d | %w", merkle, sender, startBlock, err))
return
Expand Down
28 changes: 18 additions & 10 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/rs/cors"

"github.com/JackalLabs/sequoia/file_system"
storageTypes "github.com/jackalLabs/canine-chain/v4/x/storage/types"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/JackalLabs/sequoia/proofs"
Expand Down Expand Up @@ -47,16 +48,16 @@ func (a *API) Close() error {
return a.srv.Close()
}

func (a *API) Serve(f *file_system.FileSystem, p *proofs.Prover, wallet *wallet.Wallet, chunkSize int64, myIp string) {
func (a *API) Serve(f *file_system.FileSystem, p *proofs.Prover, wallet *wallet.Wallet, queryClient storageTypes.QueryClient, myIp string, chunkSize int64) {
defer log.Info().Msg("API module stopped")
r := mux.NewRouter()

outline := types.NewOutline()

outline.RegisterGetRoute(r, "/", IndexHandler(wallet.AccAddress()))

outline.RegisterPostRoute(r, "/upload", PostFileHandler(f, p, wallet, chunkSize))
outline.RegisterPostRoute(r, "/v2/upload", PostFileHandlerV2(f, p, wallet, chunkSize))
outline.RegisterPostRoute(r, "/upload", PostFileHandler(f, p, wallet, queryClient, chunkSize))
outline.RegisterPostRoute(r, "/v2/upload", PostFileHandlerV2(f, p, wallet, queryClient, chunkSize))
outline.RegisterPostRoute(r, "/v2/status/{id}", CheckUploadStatus())
outline.RegisterPostRoute(r, "/api/jobs", ListJobsHandler())
outline.RegisterGetRoute(r, "/download/{merkle}", DownloadFileHandler(f))
Expand All @@ -69,7 +70,7 @@ func (a *API) Serve(f *file_system.FileSystem, p *proofs.Prover, wallet *wallet.
outline.RegisterGetRoute(r, "/list", ListFilesHandler(f))
outline.RegisterGetRoute(r, "/api/client/list", ListFilesHandler(f))
outline.RegisterGetRoute(r, "/api/data/fids", LegacyListFilesHandler(f))
outline.RegisterGetRoute(r, "/api/client/space", SpaceHandler(wallet.Client, wallet.AccAddress()))
outline.RegisterGetRoute(r, "/api/client/space", SpaceHandler(wallet.Client, queryClient, wallet.AccAddress()))

outline.RegisterGetRoute(r, "/ipfs/peers", IPFSListPeers(f))
outline.RegisterGetRoute(r, "/ipfs/hosts", IPFSListHosts(f))
Expand Down Expand Up @@ -99,11 +100,18 @@ func (a *API) Serve(f *file_system.FileSystem, p *proofs.Prover, wallet *wallet.
}

log.Logger.Info().Msg(fmt.Sprintf("Sequoia API now listening on %s", a.srv.Addr))
err := a.srv.ListenAndServe()
if err != nil {
if !errors.Is(err, http.ErrServerClosed) {
log.Warn().Err(err)
return
}

// Create a channel to listen for errors coming from the listener.
serverErrors := make(chan error, 1)

go func() {
serverErrors <- a.srv.ListenAndServe()
}()

// Wait for server error
err := <-serverErrors
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Warn().Err(err).Msg("server error")
return
}
}
10 changes: 9 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ func StartCmd() *cobra.Command {
log.Logger = log.Level(zerolog.ErrorLevel)
}

app, err := core.NewApp(home)
var opts []core.Option

if cmd.Flags().Changed("test_mode") {
opts = append(opts, core.WithTestMode())
}

app, err := core.NewApp(home, opts...)
if err != nil {
return err
}
Expand All @@ -61,5 +67,7 @@ func StartCmd() *cobra.Command {
},
}

cmd.Flags().Bool("test_mode", false, "run provider without chain network")

return cmd
}
37 changes: 27 additions & 10 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type ChainConfig struct {
}

type Config struct {
QueueInterval int64 `yaml:"queue_interval" mapstructure:"queue_interval"`
ProofInterval int64 `yaml:"proof_interval" mapstructure:"proof_interval"`
QueueConfig QueueConfig `yaml:"queue_config" mapstructure:"queue_config"`
StrayManagerCfg StrayManagerConfig `yaml:"stray_manager" mapstructure:"stray_manager"`
ChainCfg ChainConfig `yaml:"chain_config" mapstructure:"chain_config"`
Ip string `yaml:"domain" mapstructure:"domain"`
Expand All @@ -35,10 +35,6 @@ type Config struct {
BlockStoreConfig BlockStoreConfig `yaml:"block_store_config" mapstructure:"block_store_config"`
}

func DefaultQueueInterval() int64 {
return 10
}

func DefaultProofInterval() int64 {
return 120
}
Expand Down Expand Up @@ -113,7 +109,7 @@ func DefaultBlockStoreConfig() BlockStoreConfig {
if err != nil {
panic(err)
}
k, err := priv.Raw()
k, err := crypto.MarshalPrivateKey(priv)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -144,10 +140,32 @@ func DefaultChainConfig() ChainConfig {
}
}

type QueueConfig struct {
// seconds
QueueInterval int64 `yaml:"queue_interval" mapstructure:"queue_interval"`
// seconds
TxTimer int16 `yaml:"tx_timer" mapstructure:"tx_timer"`
QueueThreads int8 `yaml:"queue_threads" mapstructure:"queue_threads"`
// resend tx if network isn't responding
MaxRetryAttempt int8 `yaml:"max_retry_attempt" mapstructure:"max_retry_attempt"`
// group individual messages into one tx
TxBatchSize int8 `yaml:"tx_batch_size" mapstructure:"tx_batch_size"`
}

func DefaultQueueConfig() QueueConfig {
return QueueConfig{
QueueInterval: 10,
QueueThreads: 5,
MaxRetryAttempt: 100,
TxBatchSize: 45,
TxTimer: 3,
}
}

func DefaultConfig() *Config {
return &Config{
QueueInterval: DefaultQueueInterval(),
ProofInterval: DefaultProofInterval(),
QueueConfig: DefaultQueueConfig(),
StrayManagerCfg: DefaultStrayManagerConfig(),
ChainCfg: DefaultChainConfig(),
Ip: DefaultIP(),
Expand All @@ -160,8 +178,7 @@ func DefaultConfig() *Config {
}

func (c Config) MarshalZerologObject(e *zerolog.Event) {
e.Int64("QueueInterval", c.QueueInterval).
Int64("ProofInterval", c.ProofInterval).
e.Int64("ProofInterval", c.ProofInterval).
Int64("StrayCheckInterval", c.StrayManagerCfg.CheckInterval).
Int64("StrayRefreshInterval", c.StrayManagerCfg.RefreshInterval).
Int("StrayHandCount", c.StrayManagerCfg.HandCount).
Expand All @@ -180,7 +197,7 @@ func (c Config) MarshalZerologObject(e *zerolog.Event) {
}

func init() {
viper.SetDefault("QueueInterval", DefaultQueueInterval())
viper.SetDefault("QueueConfig", DefaultQueueConfig())
viper.SetDefault("ProofInterval", DefaultProofInterval())
viper.SetDefault("StrayManagerCfg", DefaultStrayManagerConfig())
viper.SetDefault("ChainCfg", DefaultChainConfig())
Expand Down
Loading
Loading