Merge pull request #171 from filecoin-project/feat/gas5

Charge per byte of object get
This commit is contained in:
Whyrusleeping 2019-08-30 11:23:02 -07:00 committed by GitHub
commit 7bf4ad8d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {