Skip to content

Commit

Permalink
Merge remote-tracking branch 'gagliardetto/multiepoch' into multiepoch
Browse files Browse the repository at this point in the history
  • Loading branch information
linuskendall committed Aug 19, 2023
2 parents 140fe42 + 7b2dacd commit cd0b071
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func newCmd_rpc() *cli.Command {
klog.Infof("Found %d directories; will start watching them for changes ...", len(dirs))
spew.Dump(dirs)

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(c.Context)
defer cancel()

err = onFileChanged(ctx, dirs, func(event fsnotify.Event) {
Expand Down Expand Up @@ -234,7 +234,7 @@ func newCmd_rpc() *cli.Command {
}
}

return multi.ListenAndServe(listenOn, listenerConfig)
return multi.ListenAndServe(c.Context, listenOn, listenerConfig)
},
}
}
Expand Down
6 changes: 5 additions & 1 deletion multiepoch-getBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex
{
// get parent slot
parentSlot := uint64(block.Meta.Parent_slot)
if parentSlot != 0 {
if parentSlot != 0 && CalcEpochForSlot(parentSlot) == epochNumber {
// NOTE: if the parent is in the same epoch, we can get it from the same epoch handler as the block;
// otherwise, we need to get it from the previous epoch (TODO: implement this)
parentBlock, err := epochHandler.GetBlock(WithSubrapghPrefetch(ctx, false), parentSlot)
if err != nil {
return &jsonrpc2.Error{
Expand All @@ -384,6 +386,8 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex
parentEntryHash := solana.HashFromBytes(parentEntryNode.Hash)
blockResp.PreviousBlockhash = parentEntryHash.String()
}
} else {
klog.Infof("parent slot is in a different epoch, not implemented yet")
}
}
tim.time("get parent block")
Expand Down
18 changes: 16 additions & 2 deletions multiepoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func LoadProxyConfig(configFilepath string) (*ProxyConfig, error) {
}

// ListeAndServe starts listening on the configured address and serves the RPC API.
func (m *MultiEpoch) ListenAndServe(listenOn string, lsConf *ListenerConfig) error {
func (m *MultiEpoch) ListenAndServe(ctx context.Context, listenOn string, lsConf *ListenerConfig) error {
handler := newMultiEpochHandler(m, lsConf)
handler = fasthttp.CompressHandler(handler)

Expand Down Expand Up @@ -206,7 +206,21 @@ func (m *MultiEpoch) ListenAndServe(listenOn string, lsConf *ListenerConfig) err
}

klog.Infof("RPC server listening on %s", listenOn)
return fasthttp.ListenAndServe(listenOn, handler)

s := &fasthttp.Server{
Handler: handler,
MaxRequestBodySize: 1024 * 1024,
}
go func() {
// listen for context cancellation
<-ctx.Done()
klog.Info("RPC server shutting down...")
defer klog.Info("RPC server shut down")
if err := s.ShutdownWithContext(ctx); err != nil {
klog.Errorf("Error while shutting down RPC server: %s", err)
}
}()
return s.ListenAndServe(listenOn)
}

func randomRequestID() string {
Expand Down

0 comments on commit cd0b071

Please sign in to comment.