Skip to content

Commit 8a3877b

Browse files
committed
feat(memo-fee): add a interface of memo fee
1 parent 23e27d9 commit 8a3877b

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,9 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
580580
throw new ContractValidateException(
581581
"Bad chain parameter id [MEMO_FEE]");
582582
}
583-
if (value < 1 || value > 1_000_000_000) {
583+
if (value < 0 || value > 1_000_000_000) {
584584
throw new ContractValidateException(
585-
"This value[MEMO_FEE] is only allowed to be in the range 1-1000_000_000");
585+
"This value[MEMO_FEE] is only allowed to be in the range 0-1000_000_000");
586586
}
587587
break;
588588
}

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
188188
"ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX".getBytes();
189189

190190
private static final byte[] MEMO_FEE = "MEMO_FEE".getBytes();
191+
private static final byte[] MEMO_FEE_HISTORY = "MEMO_FEE_HISTORY".getBytes();
191192

192193
@Autowired
193194
private DynamicPropertiesStore(@Value("properties") String dbName) {
@@ -863,7 +864,9 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
863864
try {
864865
this.getMemoFee();
865866
} catch (IllegalArgumentException e) {
866-
this.saveMemoFee(CommonParameter.getInstance().getMemoFee());
867+
long memoFee = CommonParameter.getInstance().getMemoFee();
868+
this.saveMemoFee(memoFee);
869+
this.saveMemoFeeHistory("0:" + memoFee);
867870
}
868871
}
869872

@@ -2547,6 +2550,17 @@ public void saveMemoFee(long value) {
25472550
this.put(MEMO_FEE, new BytesCapsule(ByteArray.fromLong(value)));
25482551
}
25492552

2553+
public String getMemoFeeHistory() {
2554+
return Optional.ofNullable(getUnchecked(MEMO_FEE_HISTORY))
2555+
.map(BytesCapsule::getData)
2556+
.map(ByteArray::toStr)
2557+
.orElseThrow(() -> new IllegalArgumentException("not found MEMO_FEE_HISTORY"));
2558+
}
2559+
2560+
public void saveMemoFeeHistory(String value) {
2561+
this.put(MEMO_FEE_HISTORY, new BytesCapsule(ByteArray.fromString(value)));
2562+
}
2563+
25502564
private static class DynamicResourceProperties {
25512565

25522566
private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,5 +4085,13 @@ public Block getBlock(GrpcAPI.BlockReq request) {
40854085
return block.toBuilder().clearTransactions().build();
40864086
}
40874087

4088+
public String getMemoFeePrices() {
4089+
try {
4090+
return chainBaseManager.getDynamicPropertiesStore().getMemoFeeHistory();
4091+
} catch (Exception e) {
4092+
logger.error("getMemoFeePrices failed, error is {}", e.getMessage());
4093+
}
4094+
return null;
4095+
}
40884096
}
40894097

framework/src/main/java/org/tron/core/consensus/ProposalService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
290290
}
291291
case MEMO_FEE: {
292292
manager.getDynamicPropertiesStore().saveMemoFee(entry.getValue());
293+
// update memo fee history
294+
manager.getDynamicPropertiesStore().saveMemoFeeHistory(
295+
manager.getDynamicPropertiesStore().getMemoFeeHistory()
296+
+ "," + proposalCapsule.getExpirationTime() + ":" + entry.getValue());
293297
break;
294298
}
295299
default:

framework/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public class FullNodeHttpApiService implements Service {
293293
private GetBandwidthPricesServlet getBandwidthPricesServlet;
294294
@Autowired
295295
private GetBlockServlet getBlockServlet;
296+
@Autowired
297+
private GetMemoFeePricesServlet getMemoFeePricesServlet;
296298

297299
private static String getParamsFile(String fileName) {
298300
InputStream in = Thread.currentThread().getContextClassLoader()
@@ -542,6 +544,7 @@ public void start() {
542544
context.addServlet(new ServletHolder(getBandwidthPricesServlet),
543545
"/wallet/getbandwidthprices");
544546
context.addServlet(new ServletHolder(getBlockServlet), "/wallet/getblock");
547+
context.addServlet(new ServletHolder(getMemoFeePricesServlet), "/wallet/getmemofee");
545548

546549
int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber();
547550
if (maxHttpConnectNumber > 0) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.tron.core.services.http;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import javax.servlet.http.HttpServletRequest;
5+
import javax.servlet.http.HttpServletResponse;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.stereotype.Component;
9+
import org.tron.core.Wallet;
10+
11+
12+
@Component
13+
@Slf4j(topic = "API")
14+
public class GetMemoFeePricesServlet extends RateLimiterServlet {
15+
16+
@Autowired
17+
private Wallet wallet;
18+
19+
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
20+
try {
21+
String reply = wallet.getMemoFeePrices();
22+
if (reply != null) {
23+
JSONObject jsonObject = new JSONObject();
24+
jsonObject.put("prices", reply);
25+
response.getWriter().println(jsonObject);
26+
} else {
27+
response.getWriter().println("{}");
28+
}
29+
} catch (Exception e) {
30+
Util.processError(e, response);
31+
}
32+
}
33+
34+
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
35+
doGet(request, response);
36+
}
37+
}

0 commit comments

Comments
 (0)