Skip to content
Merged
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
40 changes: 20 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,44 @@ endef
.PHONY: build/actionindex
build/actionindex:
@if [ "$(call needs_rebuild,actionindex,services/actionindex)" = "1" ]; then \
echo "==> Building actionindex (CGO_ENABLED=0)"; \
CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/actionindex ./services/actionindex/cmd/actionindex; \
echo "==> Building actionindex"; \
go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/actionindex ./services/actionindex/cmd/actionindex; \
else \
echo "==> actionindex is up to date"; \
fi

.PHONY: build/coreverify
build/coreverify:
@if [ "$(call needs_rebuild,coreverify,services/coreverify)" = "1" ]; then \
echo "==> Building coreverify (CGO_ENABLED=0)"; \
CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/coreverify ./services/coreverify/cmd/coreverify; \
echo "==> Building coreverify"; \
go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/coreverify ./services/coreverify/cmd/coreverify; \
else \
echo "==> coreverify is up to date"; \
fi

.PHONY: build/apiproxy
build/apiproxy:
@if [ "$(call needs_rebuild,apiproxy,services/apiproxy)" = "1" ]; then \
echo "==> Building apiproxy (CGO_ENABLED=0)"; \
CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/apiproxy ./services/apiproxy/cmd/apiproxy; \
echo "==> Building apiproxy"; \
go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/apiproxy ./services/apiproxy/cmd/apiproxy; \
else \
echo "==> apiproxy is up to date"; \
fi

.PHONY: build/coreindex
build/coreindex:
@if [ "$(call needs_rebuild,coreindex,services/coreindex)" = "1" ]; then \
echo "==> Building coreindex (CGO_ENABLED=0)"; \
CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/coreindex ./services/coreindex/cmd/coreindex; \
echo "==> Building coreindex"; \
go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/coreindex ./services/coreindex/cmd/coreindex; \
else \
echo "==> coreindex is up to date"; \
fi

.PHONY: build/txindex
build/txindex:
@if [ "$(call needs_rebuild,txindex,services/txindex)" = "1" ]; then \
echo "==> Building txindex (CGO_ENABLED=0)"; \
CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/txindex ./services/txindex/cmd/txindex; \
echo "==> Building txindex"; \
go build -ldflags "-X main.Version=$(VERSION)" -o $(BINDIR)/txindex ./services/txindex/cmd/txindex; \
else \
echo "==> txindex is up to date"; \
fi
Expand All @@ -184,28 +184,28 @@ build/txindex:

.PHONY: install/actionindex
install/actionindex:
@echo "==> Installing actionindex (CGO_ENABLED=0)"
@CGO_ENABLED=0 go install ./services/actionindex/cmd/actionindex
@echo "==> Installing actionindex"
@go install ./services/actionindex/cmd/actionindex

.PHONY: install/coreverify
install/coreverify:
@echo "==> Installing coreverify (CGO_ENABLED=0)"
@CGO_ENABLED=0 go install ./services/coreverify/cmd/coreverify
@echo "==> Installing coreverify"
@go install ./services/coreverify/cmd/coreverify

.PHONY: install/apiproxy
install/apiproxy:
@echo "==> Installing apiproxy (CGO_ENABLED=0)"
@CGO_ENABLED=0 go install ./services/apiproxy/cmd/apiproxy
@echo "==> Installing apiproxy"
@go install ./services/apiproxy/cmd/apiproxy

.PHONY: install/coreindex
install/coreindex:
@echo "==> Installing coreindex (CGO_ENABLED=0)"
@CGO_ENABLED=0 go install ./services/coreindex/cmd/coreindex
@echo "==> Installing coreindex"
@go install ./services/coreindex/cmd/coreindex

.PHONY: install/txindex
install/txindex:
@echo "==> Installing txindex (CGO_ENABLED=0)"
@CGO_ENABLED=0 go install ./services/txindex/cmd/txindex
@echo "==> Installing txindex"
@go install ./services/txindex/cmd/txindex

# =============================================================================
# Release Targets
Expand Down
4 changes: 1 addition & 3 deletions libraries/abicache/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"syscall"

goeosio "github.com/greymass/go-eosio/pkg/chain"
"github.com/greymass/roborovski/libraries/chain"
)

type Reader struct {
Expand Down Expand Up @@ -198,9 +197,8 @@ func (r *Reader) Decode(contract, action uint64, data []byte, atBlock uint32) (m
cachedABI = &abi
}

actionName := chain.NameToString(action)
reader := bytes.NewReader(data)
decoded, err := cachedABI.Decode(reader, actionName)
decoded, err := cachedABI.DecodeAction(reader, goeosio.Name(action))
if err != nil {
return nil, fmt.Errorf("failed to decode action: %w", err)
}
Expand Down
40 changes: 23 additions & 17 deletions libraries/actionstream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ func DefaultClientConfig() ClientConfig {
}

type Action struct {
GlobalSeq uint64
BlockNum uint32
BlockTime uint32
Contract string
Action string
Receiver string
ActionData []byte
GlobalSeq uint64
BlockNum uint32
BlockTime uint32
Contract string
Action string
Receiver string
ActionData []byte
CpuUsageUs uint32
NetUsageWords uint32
}

type Filter struct {
Expand Down Expand Up @@ -490,7 +492,7 @@ func (c *Client) writeMessage(w io.Writer, msgType uint8, payload []byte) error
}

func (c *Client) decodeAction(payload []byte) (Action, error) {
if len(payload) < 40 {
if len(payload) < 48 {
return Action{}, errors.New("action payload too short")
}

Expand All @@ -500,20 +502,24 @@ func (c *Client) decodeAction(payload []byte) (Action, error) {
contract := binary.LittleEndian.Uint64(payload[16:24])
actionName := binary.LittleEndian.Uint64(payload[24:32])
receiver := binary.LittleEndian.Uint64(payload[32:40])
cpuUsageUs := binary.LittleEndian.Uint32(payload[40:44])
netUsageWords := binary.LittleEndian.Uint32(payload[44:48])

var actionData []byte
if len(payload) > 40 {
actionData = payload[40:]
if len(payload) > 48 {
actionData = payload[48:]
}

return Action{
GlobalSeq: globalSeq,
BlockNum: blockNum,
BlockTime: blockTime,
Contract: chain.NameToString(contract),
Action: chain.NameToString(actionName),
Receiver: chain.NameToString(receiver),
ActionData: actionData,
GlobalSeq: globalSeq,
BlockNum: blockNum,
BlockTime: blockTime,
Contract: chain.NameToString(contract),
Action: chain.NameToString(actionName),
Receiver: chain.NameToString(receiver),
ActionData: actionData,
CpuUsageUs: cpuUsageUs,
NetUsageWords: netUsageWords,
}, nil
}

Expand Down
20 changes: 15 additions & 5 deletions libraries/actionstream/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ func TestNewClient(t *testing.T) {
func TestDecodeAction(t *testing.T) {
client := NewClient("localhost:9411", Filter{}, 0, DefaultClientConfig())

payload := make([]byte, 40)
payload := make([]byte, 48)
binary.LittleEndian.PutUint64(payload[0:8], 12345)
binary.LittleEndian.PutUint32(payload[8:12], 1000)
binary.LittleEndian.PutUint32(payload[12:16], 1700000000)
binary.LittleEndian.PutUint64(payload[16:24], 0x5530EA033C80A555)
binary.LittleEndian.PutUint64(payload[24:32], 0x00000000A89C6360)
binary.LittleEndian.PutUint64(payload[32:40], 0x5530EA033C80A555)
binary.LittleEndian.PutUint32(payload[40:44], 500)
binary.LittleEndian.PutUint32(payload[44:48], 20)

action, err := client.decodeAction(payload)
if err != nil {
Expand All @@ -50,19 +52,27 @@ func TestDecodeAction(t *testing.T) {
if action.BlockTime != 1700000000 {
t.Errorf("expected BlockTime 1700000000, got %d", action.BlockTime)
}
if action.CpuUsageUs != 500 {
t.Errorf("expected CpuUsageUs 500, got %d", action.CpuUsageUs)
}
if action.NetUsageWords != 20 {
t.Errorf("expected NetUsageWords 20, got %d", action.NetUsageWords)
}
}

func TestDecodeActionWithData(t *testing.T) {
client := NewClient("localhost:9411", Filter{}, 0, DefaultClientConfig())

payload := make([]byte, 48)
payload := make([]byte, 56)
binary.LittleEndian.PutUint64(payload[0:8], 100)
binary.LittleEndian.PutUint32(payload[8:12], 500)
binary.LittleEndian.PutUint32(payload[12:16], 1600000000)
binary.LittleEndian.PutUint64(payload[16:24], 0)
binary.LittleEndian.PutUint64(payload[24:32], 0)
binary.LittleEndian.PutUint64(payload[32:40], 0)
copy(payload[40:], []byte("testdata"))
binary.LittleEndian.PutUint32(payload[40:44], 0)
binary.LittleEndian.PutUint32(payload[44:48], 0)
copy(payload[48:], []byte("testdata"))

action, err := client.decodeAction(payload)
if err != nil {
Expand Down Expand Up @@ -634,7 +644,7 @@ func TestDialReceivesBatch(t *testing.T) {
payload := make([]byte, length-1)
conn.Read(payload)

actionPayload := make([]byte, 40)
actionPayload := make([]byte, 48)
binary.LittleEndian.PutUint64(actionPayload[0:8], 999)
binary.LittleEndian.PutUint32(actionPayload[8:12], 100)
binary.LittleEndian.PutUint32(actionPayload[12:16], 1700000000)
Expand Down Expand Up @@ -822,7 +832,7 @@ func TestRecvLoopReceivesActions(t *testing.T) {
close(serverReady)

for i := uint64(0); i < 3; i++ {
actionPayload := make([]byte, 40)
actionPayload := make([]byte, 48)
binary.LittleEndian.PutUint64(actionPayload[0:8], 1000+i)
binary.LittleEndian.PutUint32(actionPayload[8:12], uint32(100+i))
binary.LittleEndian.PutUint32(actionPayload[12:16], 1700000000)
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type ActionTrace struct {
ProducerBlockID string `json:"producer_block_id"`
AccountRAMDeltas []AccountDelta `json:"account_ram_deltas"`

CpuUsageUs uint32 `json:"-"`
NetUsageWords uint32 `json:"-"`
GlobalSeqUint64 uint64 `json:"-"`
}

Expand Down
32 changes: 30 additions & 2 deletions libraries/compression/zstd_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,40 @@ func putDecoder(d *zstd.Decoder) {
decoderPool.Put(d)
}

var (
encoderMu sync.RWMutex
encoderCache = map[int]*zstd.Encoder{}
)

func getEncoder(level int) (*zstd.Encoder, error) {
encoderMu.RLock()
enc, ok := encoderCache[level]
encoderMu.RUnlock()
if ok {
return enc, nil
}

encoderMu.Lock()
defer encoderMu.Unlock()
if enc, ok = encoderCache[level]; ok {
return enc, nil
}
enc, err := zstd.NewWriter(nil,
zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)),
zstd.WithEncoderConcurrency(1),
)
if err != nil {
return nil, err
}
encoderCache[level] = enc
return enc, nil
}

func ZstdCompressLevel(dst, src []byte, level int) ([]byte, error) {
enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)))
enc, err := getEncoder(level)
if err != nil {
return nil, err
}
defer enc.Close()
return enc.EncodeAll(src, dst[:0]), nil
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/corereader/canonical_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func filterBlockInto(bf *blockFilter, notif RawBlock, actionFilter ActionFilterF
GlobalSeq: globalSeq,
TrxIndex: info.TrxIndex,
IsAuthorizer: isAuth,
Receiver: info.Receiver,
})
if minSeq == 0 || globalSeq < minSeq {
minSeq = globalSeq
Expand Down Expand Up @@ -377,6 +378,7 @@ func filterBlockInto(bf *blockFilter, notif RawBlock, actionFilter ActionFilterF
GlobalSeq: globalSeq,
TrxIndex: info.TrxIndex,
IsAuthorizer: true,
Receiver: info.Receiver,
})
if minSeq == 0 || globalSeq < minSeq {
minSeq = globalSeq
Expand Down Expand Up @@ -504,6 +506,7 @@ func filterBlockIntoTimed(bf *blockFilter, notif RawBlock, actionFilter ActionFi
GlobalSeq: globalSeq,
TrxIndex: info.TrxIndex,
IsAuthorizer: isAuth,
Receiver: info.Receiver,
})
if minSeq == 0 || globalSeq < minSeq {
minSeq = globalSeq
Expand Down Expand Up @@ -562,6 +565,7 @@ func filterBlockIntoTimed(bf *blockFilter, notif RawBlock, actionFilter ActionFi
GlobalSeq: globalSeq,
TrxIndex: info.TrxIndex,
IsAuthorizer: true,
Receiver: info.Receiver,
})
if minSeq == 0 || globalSeq < minSeq {
minSeq = globalSeq
Expand Down
Loading
Loading