From e6b83d94280772d9c3e92b92248295199611bacf Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 30 Aug 2019 18:05:54 +0200 Subject: [PATCH] Charge per byte of object get License: MIT Signed-off-by: Jakub Sztandera --- chain/vm/vm.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 5f339f39e..ed1d9b556 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -30,6 +30,7 @@ const ( gasInvoke = 5 gasGetObj = 10 + gasGetPerByte = 1 gasPutObj = 20 gasPutPerByte = 2 gasCommit = 50 @@ -230,7 +231,15 @@ func (bs *gasChargingBlocks) GetBlock(ctx context.Context, c cid.Cid) (block.Blo if err := bs.chargeGas(gasGetObj); err != nil { return nil, err } - return bs.under.GetBlock(ctx, c) + blk, err := bs.under.GetBlock(ctx, c) + if err != nil { + return nil, err + } + if err := bs.chargeGas(uint64(len(blk.RawData())) * gasGetPerByte); err != nil { + return nil, err + } + + return blk, nil } func (bs *gasChargingBlocks) AddBlock(blk block.Block) error {