您正在查看: Other 分类下的文章

Ubuntu18.04上源码安装Haproxy2.x

准备编译安装HAProxy的基础环境

sudo apt install make gcc build-essential libssl-dev zlib1g-dev libpcre3 libpcre3-dev libsystemd-dev libreadline-dev -y

编译安装lua

lua为HAProxy支持基于其实现功能扩展
注:HAProxy要求的lua最低版本为5.3

sudo wget -P /usr/local/src/ http://www.lua.org/ftp/lua-5.3.5.tar.gz
cd /usr/local/src/
sudo tar xf lua-5.3.5.tar.gz
cd lua-5.3.5/src/
sudo make linux

查看编译后的版本

surou@DESKTOP-CRS8RL6:/usr/local/src/lua-5.3.5/src$ ./lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

编译安装HAProxy

安装基础环境

sudo apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev  gcc openssh-server iotop unzip libreadline-dev libsystemd-dev

clone haproxy

git clone https://github.com/haproxy/haproxy.git
git checkout v2.3-dev5

编译源代码

make -j `lscpu |awk 'NR==4{print $2}'` ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_LUA=1 LUA_INC=/usr/local/src/lua-5.3.5/src/ LUA_LIB=/usr/local/src/lua-5.3.5/src/ PREFIX=/apps/haproxy && make install PREFIX=./dist/haproxy

编译完,查看当前目录

cd dist/haproxy/sbin

查看版本

./haproxy -v
surou@DESKTOP-CRS8RL6:~/dist/haproxy/sbin$ ./haproxy -v
HA-Proxy version 2.3-dev5-7faeea-1 2020/09/26 - https://haproxy.org/
Status: development branch - not safe for use in production.
Known bugs: https://github.com/haproxy/haproxy/issues?q=is:issue+is:open
Running on: Linux 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64

参考

https://www.cnblogs.com/molson/p/13341108.html

箭头函数 与 forEach

array.forEach(function(item,index){
}.bind(this));

等同于

array.forEach((item,index) =>{
});

转载:https://www.cnblogs.com/guomengkai/p/11392958.html

compound-finance compound-protocol 存和借利率合约分析

计算每块供应率
(github)

 /**
     * @notice Returns the current per-block supply interest rate for this cToken
     * @return The supply interest rate per block, scaled by 1e18
     */
function supplyRatePerBlock() external view returns (uint) {
    return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa);
}

返回-每块的供应利率,按1e18缩放
跟一下关键参数

getCashPrior()

github

/**
     * @notice Gets balance of this contract in terms of the underlying
     * @dev This excludes the value of the current message, if any
     * @return The quantity of underlying tokens owned by this contract
     */
function getCashPrior() internal view returns (uint) {
    EIP20Interface token = EIP20Interface(underlying);
    return token.balanceOf(address(this));
}

代码逻辑为,获取当前合约地址拥有的基础代币余额数量

totalBorrows

借出的代币总数

totalReserves

存入的代币总数(储备金)

reserveFactorMantissa

市场的当前储备系数

getSupplyRate

(github)

 /**
     * @notice Calculates the current supply rate per block
     * @param cash The amount of cash in the market
     * @param borrows The amount of borrows in the market
     * @param reserves The amount of reserves in the market
     * @param reserveFactorMantissa The current reserve factor for the market
     * @return The supply rate percentage per block as a mantissa (scaled by 1e18)
     */
function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) public view returns (uint) {
    uint oneMinusReserveFactor = uint(1e18).sub(reserveFactorMantissa);        // 单量减去储备的系数
    uint borrowRate = getBorrowRate(cash, borrows, reserves);                  // 获取借出的利率
    uint rateToPool = borrowRate.mul(oneMinusReserveFactor).div(1e18);         // 将借出的利率缩小储备系数倍数
    return utilizationRate(cash, borrows, reserves).mul(rateToPool).div(1e18); // 市场利用率/缩小储备系数后的借出利率
}
附加

add sub mul div 来自SafeMath库,对等是加减乘除

utilizationRate 计算市场利用率

github

/**
     * @notice Calculates the utilization rate of the market: `borrows / (cash + borrows - reserves)`
     * @param cash The amount of cash in the market
     * @param borrows The amount of borrows in the market
     * @param reserves The amount of reserves in the market (currently unused)
     * @return The utilization rate as a mantissa between [0, 1e18]
     */
function utilizationRate(uint cash, uint borrows, uint reserves) public pure returns (uint) {
    // Utilization rate is 0 when there are no borrows
    if (borrows == 0) {
        return 0;
    }
    return borrows.mul(1e18).div(cash.add(borrows).sub(reserves)); // 借出/(账户剩余+借出-存入)
    // 借出,就是发币合约把代币转给其他的账户,当其他账户存币时,再转回发币合约账户
}

getBorrowRate 获取每个块的当前借入利率

 /**
     * @notice Calculates the current borrow rate per block, with the error code expected by the market
     * @param cash The amount of cash in the market
     * @param borrows The amount of borrows in the market
     * @param reserves The amount of reserves in the market
     * @return The borrow rate percentage per block as a mantissa (scaled by 1e18)
     */
function getBorrowRate(uint cash, uint borrows, uint reserves) public view returns (uint) {
    uint util = utilizationRate(cash, borrows, reserves); //计算市场利用率

    if (util <= kink) {
        return util.mul(multiplierPerBlock).div(1e18).add(baseRatePerBlock);
    } else {
        uint normalRate = kink.mul(multiplierPerBlock).div(1e18).add(baseRatePerBlock);
        uint excessUtil = util.sub(kink);
        return excessUtil.mul(jumpMultiplierPerBlock).div(1e18).add(normalRate);
    }
}
kink

应用跳转乘数的利用率点,当利用率小于这个配置值时,走相应逻辑

multiplierPerBlock

利用率乘数,得出利率的斜率

multiplierPerYear

利用率的利率增长率(按1e18缩放
multiplierPerBlock = multiplierPerYear.div(blocksPerYear);

jumpMultiplierPerBlock

jumpMultiplierPerBlock = jumpMultiplierPerYear.div(blocksPerYear);

baseRatePerYear

初始值,每年的基础利率

blocksPerYear

利率模型假设的每年大约的块数

baseRatePerBlock

基本利率是利用率为0时的y截距,
baseRatePerBlock = baseRatePerYear.div(blocksPerYear);

jumpMultiplierPerBlock

达到指定的利用率点后的multiplierPerBlock

总结

稍后补充

参考

https://www.jinse.com/blockchain/485426.html

chrome清除缓存、不使用缓存而刷新快捷键

Ctrl+Shift+Del 清除Google浏览器缓存的快捷键
Ctrl+Shift+R 重新加载当前网页而不使用缓存内容
Ctrl + F5 去除缓存+刷新快捷键

yarn错误The engine "node" is incompatible with this module

 yarn config set ignore-engines true